Skip to content

Commit

Permalink
feat: java code
Browse files Browse the repository at this point in the history
  • Loading branch information
azl397985856 authored Sep 29, 2022
2 parents 091380e + 2ac0cc7 commit 3c546df
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion problems/191.number-of-1-bits.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ https://leetcode-cn.com/problems/number-of-1-bits/

## 代码

语言支持:JS, C++Python
语言支持:JS, C++,Python,Java

JavaScript Code:

Expand Down Expand Up @@ -125,6 +125,23 @@ class Solution(object):
return count
```


Java Code:

```java
public class Solution {
public int hammingWeight(int n) {
int count = 0;
for (int i = 0; i < 32; i++) {
if ((n & (1 << i)) != 0) {
count++;
}
}
return count;
}
}
```

**复杂度分析**

- 时间复杂度:$O(logN)$
Expand Down

0 comments on commit 3c546df

Please sign in to comment.