We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 97978b3 commit fd63601Copy full SHA for fd63601
number-of-1-bits/minji-go.java
@@ -0,0 +1,17 @@
1
+/**
2
+ * <a href="https://leetcode.com/problems/number-of-1-bits/">week03-2.number-of-1-bits</a>
3
+ * <li>Description: returns the number of set bits in its binary representation</li>
4
+ * <li>Topics: Divide and Conquer, Bit Manipulation </li>
5
+ * <li>Time Complexity: O(logN), Runtime 0ms </li>
6
+ * <li>Space Complexity: O(1), Memory 41.95MB </li>
7
+ */
8
+class Solution {
9
+ public int hammingWeight(int n) {
10
+ int count = 0;
11
+ while(n != 0) {
12
+ n &= (n-1);
13
+ count++;
14
+ }
15
+ return count;
16
17
+}
0 commit comments