Skip to content

Commit 27861d6

Browse files
committed
add Sum of Two Integers solution
1 parent 55d8a16 commit 27861d6

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* [Problem]: [371] Sum of Two Integers
3+
* (https://leetcode.com/problems/sum-of-two-integers/description/)
4+
*/
5+
function getSum(a: number, b: number): number {
6+
// 시간복잡도 O(n)
7+
// 공간복잡도 O(1)
8+
while (b !== 0) {
9+
const carry = a & b;
10+
a = a ^ b;
11+
b = carry << 1;
12+
}
13+
return a;
14+
}

0 commit comments

Comments
 (0)