We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 36f2f83 commit 9754d83Copy full SHA for 9754d83
README.md
@@ -1,2 +1,7 @@
1
# leetcode
2
+
3
LeetCode Problems' Solutions in JavaScript
4
5
+## easy
6
7
+1. [计数质数](./easy/countPrimes/countPrimis.js)
algorithms/easy/hammingWeight/hammingWeight.js
@@ -0,0 +1,17 @@
+// description: https://leetcode-cn.com/explore/interview/card/top-interview-questions-easy/26/others/64/
+// 位1的个数
+/**
+ * @param {number} n - a positive integer
+ * @return {number}
+ */
8
+var hammingWeight = function(n) {
9
+ var sn = n.toString(2);
10
+ var count = 0;
11
+ for (var i = 0, len = sn.length; i < len; i++) {
12
+ if (sn.charAt(i) === "1") {
13
+ count = count + 1;
14
+ }
15
16
+ return count;
17
+};
0 commit comments