Skip to content

Commit a73f5ca

Browse files
committed
solve: sum of two integers
1 parent 9402dca commit a73f5ca

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

sum-of-two-integers/wogha95.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* TC: O(Bit)
3+
* 올림 비트가 0일때까지 while을 실행하게된다.
4+
*
5+
* SC: O(1)
6+
*
7+
* Bit: 2진수 a 와 b 중 비트 길이가 긴 것의 비트 길이
8+
*/
9+
10+
/**
11+
* @param {number} a
12+
* @param {number} b
13+
* @return {number}
14+
*/
15+
var getSum = function (a, b) {
16+
while (b !== 0) {
17+
const carry = (a & b) << 1;
18+
a = a ^ b;
19+
b = carry;
20+
}
21+
22+
return a;
23+
};

0 commit comments

Comments
 (0)