Skip to content

Commit 0f82241

Browse files
update post
1 parent a96e7ee commit 0f82241

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

_posts/2024-02-20-leetcode-191.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,21 @@ class Solution:
5959

6060
## 참고
6161

62-
지난번 binary문제에서도 이야기 했지만 bit 연산자에 대한 설명은 [FAQ: What do the operators <<, >>, &, |, ~, and ^ do?](https://wiki.python.org/moin/BitwiseOperators)를 참고하면 좋을 것 같다.
62+
지난번 binary문제에서도 이야기 했지만 bit 연산자에 대한 설명은 [FAQ: What do the operators `<<, >>, &, |, ~, and ^` do?](https://wiki.python.org/moin/BitwiseOperators)를 참고하면 좋을 것 같다.
63+
64+
## 자바로 다시 풀기 (24.05.25)
65+
66+
```java
67+
public int hammingWeight(int n) {
68+
int count = 0;
69+
while (n != 0) {
70+
count += n % 2;
71+
n = n >> 1;
72+
}
73+
return count;
74+
}
75+
```
76+
77+
### TC, SC
78+
79+
시간 복잡도는 O(logn)이고, 공간 복잡도는 O(1)이다. logn 인 이유는 bit의 수는 log에 따르기 때문이다.

0 commit comments

Comments
 (0)