Skip to content

Commit 5e67846

Browse files
authored
[ PS ] : Sum of Two Integers
1 parent cb616a0 commit 5e67846

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

sum-of-two-integers/uraflower.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* +, - 연산자를 사용하지 않고 a, b를 더하는 함수
3+
* @param {number} a
4+
* @param {number} b
5+
* @return {number}
6+
*/
7+
const getSum = function (a, b) {
8+
while (b !== 0) {
9+
[a, b] = [a ^ b, (a & b) << 1]
10+
}
11+
12+
return a;
13+
};
14+
15+
// 시간복잡도: O(1)
16+
// 공간복잡도: O(1)

0 commit comments

Comments
 (0)