Skip to content

Commit fbdac2d

Browse files
update post
1 parent c17486d commit fbdac2d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

_posts/2024-01-31-leetcode-371.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ tags:
1414
bit operation,
1515
int,
1616
unbounded,
17+
java,
18+
Math,
19+
Bit Manipulation,
1720
]
1821
date: 2024-01-31 12:00:00 +0900
1922
---
@@ -97,3 +100,24 @@ python도 음수인지 양수인지 체크를 별도의 부호 비트를 사용
97100
## 참고
98101

99102
bit 연산자에 대한 설명은 [FAQ: What do the operators `<<, >>, &, |, ~, and ^` do?](https://wiki.python.org/moin/BitwiseOperators)를 참고하면 좋을 것 같다.
103+
104+
## 자바로 다시 풀기 (240731)
105+
106+
```java
107+
class Solution {
108+
public int getSum(int a, int b) {
109+
while (b != 0) {
110+
int _a = (a ^ b);
111+
int _b = ((a & b) << 1);
112+
a = _a;
113+
b = _b;
114+
}
115+
116+
return a;
117+
}
118+
}
119+
```
120+
121+
### TC, SC
122+
123+
시간 복잡도는 O(1), 공간복잡도는 O(1) 이다. 최악의 경우 b의 비트수(32)만큼 반복문이 진행된다.

0 commit comments

Comments
 (0)