function g(n){ var n = n.toString(2); var count = 0; for(var i=0;i{ if(n[i] = = "1") count ; } return count; }
I thought it was very troublesome to write like this, but I suddenly thought if I could use the split method of js. Realize the calculation of the number of 1, and the parameter of split is regular
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn