Skip to content

Commit 9754d83

Browse files
committed
update
1 parent 36f2f83 commit 9754d83

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
# leetcode
2+
23
LeetCode Problems' Solutions in JavaScript
4+
5+
## easy
6+
7+
1. [计数质数](./easy/countPrimes/countPrimis.js)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// description: https://leetcode-cn.com/explore/interview/card/top-interview-questions-easy/26/others/64/
2+
// 位1的个数
3+
4+
/**
5+
* @param {number} n - a positive integer
6+
* @return {number}
7+
*/
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

Comments
 (0)