Skip to content

Commit 55f4c9f

Browse files
committed
🔥 Numer of 1 Bits
1 parent 4a1a356 commit 55f4c9f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ Solutions of LeetCode Blind 75 Problems in JavaScript
1717
| [3Sum](./3sum.js) | <img src="https://img.shields.io/badge/-Medium-orange" /> | `Array`, `Two Pointers`, `Sorting` | [:link:](https://leetcode.com/problems/3sum/) |
1818
| [Container With Most Water](./container-with-most-water.js) | <img src="https://img.shields.io/badge/-Medium-orange" /> | `Array`, `Two Pointers`, `Greedy` | [:link:](https://leetcode.com/problems/container-with-most-water/) |
1919
| [Sum of Two Integers](./sum-of-two-integers.js) | <img src="https://img.shields.io/badge/-Medium-orange" /> | `Math`, `Bit Manipulation` | [:link:](https://leetcode.com/problems/sum-of-two-integers/) |
20+
| [Number of 1 Bits](./number-of-1-bits.js) | <img src="https://img.shields.io/badge/-Easy-green" /> | `Bit Manipulation` | [:link:](https://leetcode.com/problems/number-of-1-bits/) |

number-of-1-bits.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const hammingWeight = (n) => {
2+
let result = 0;
3+
4+
while (n) {
5+
result += n % 2; // Either 1 or 0
6+
n = n >> 1; // Right Shift by 1
7+
}
8+
9+
return result;
10+
};

0 commit comments

Comments
 (0)