Skip to content

Commit 5a960f8

Browse files
committed
Create f-exuan21.java
number of 1 bits solutions
1 parent b21432d commit 5a960f8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

number-of-1-bits/f-exuan21.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// time : O(1)
2+
// space : O(1)
3+
4+
class Solution {
5+
public int hammingWeight(int n) {
6+
int count = 0;
7+
8+
while(n != 0) {
9+
if((n&1) == 1) count++;
10+
n = n >> 1;
11+
}
12+
13+
return count;
14+
}
15+
}
16+

0 commit comments

Comments
 (0)