Skip to content

Commit 0d36d5d

Browse files
week14 mission sum-of-two-integers
1 parent 25f0136 commit 0d36d5d

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
- 문제: https://leetcode.com/problems/sum-of-two-integers/
2+
- 풀이: https://algorithm.jonghoonpark.com/2024/01/31/leetcode-371
3+
4+
```java
5+
class Solution {
6+
public int getSum(int a, int b) {
7+
while (b != 0) {
8+
int _a = (a ^ b);
9+
int _b = ((a & b) << 1);
10+
a = _a;
11+
b = _b;
12+
}
13+
14+
return a;
15+
}
16+
}
17+
```
18+
19+
### TC, SC
20+
21+
시간 복잡도는 O(1), 공간복잡도는 O(1) 이다. 최악의 경우 b의 비트수(32)만큼 반복문이 진행된다.

0 commit comments

Comments
 (0)