Skip to content

Commit fff021e

Browse files
feat: add ts solution to lc problem: No.191 (#2035)
Co-authored-by: iam-abhishek-yadav <abhishekyadav.recs@gmail.com>
1 parent 610988f commit fff021e

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

solution/0100-0199/0191.Number of 1 Bits/README.md

+12
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,18 @@ int hammingWeight(uint32_t n) {
261261
}
262262
```
263263
264+
### **Typescript**
265+
```ts
266+
function hammingWeight(n: number): number {
267+
let ans: number = 0;
268+
while (n !== 0) {
269+
ans++;
270+
n &= (n - 1);
271+
}
272+
return ans;
273+
}
274+
```
275+
264276
### **...**
265277

266278
```

solution/0100-0199/0191.Number of 1 Bits/README_EN.md

+13
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,19 @@ int hammingWeight(uint32_t n) {
211211
}
212212
```
213213
214+
### **Typescript**
215+
```ts
216+
function hammingWeight(n: number): number {
217+
let ans: number = 0;
218+
while (n !== 0) {
219+
ans++;
220+
n &= (n - 1);
221+
}
222+
return ans;
223+
}
224+
```
225+
226+
214227
### **...**
215228

216229
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function hammingWeight(n: number): number {
2+
let ans: number = 0;
3+
while (n !== 0) {
4+
ans++;
5+
n &= (n - 1);
6+
}
7+
return ans;
8+
}

0 commit comments

Comments
 (0)