Skip to content

Commit e7a3044

Browse files
committed
sum-of-two-integers
1 parent 2a99ebe commit e7a3044

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

sum-of-two-integers/krokerdile.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @param {number} a
3+
* @param {number} b
4+
* @return {number}
5+
*/
6+
function getSum(a, b) {
7+
while (b !== 0) {
8+
const sum = a ^ b; // 자리올림 없는 합
9+
const carry = (a & b) << 1; // 자리올림 비트
10+
11+
a = sum;
12+
b = carry;
13+
}
14+
15+
return a;
16+
}

0 commit comments

Comments
 (0)