Skip to content

Commit 67e7fac

Browse files
committed
feat(soobing): week9 > sum-of-two-integers
1 parent c4f616e commit 67e7fac

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* ๋ฌธ์ œ ์„ค๋ช…
3+
* - ๋‘ ์ •์ˆ˜์˜ ํ•ฉ์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋ฌธ์ œ (๋น„ํŠธ ์—ฐ์‚ฐ์„ ํ†ตํ•ด์„œ)
4+
*
5+
* ์•„์ด๋””์–ด
6+
* - ๋ฐ˜์˜ฌ๋ฆผ์€ AND(&) + ์™ผ์ชฝ shift 1, ๋ง์…ˆ์€ XOR(^) ์—ฐ์‚ฐ์„ ํ†ตํ•ด์„œ ํ•œ๋‹ค.
7+
* - ๋ฐ˜์˜ฌ๋ฆผ์ด 0์ด ๋  ๋•Œ๊นŒ์ง€ ๋ฐ˜๋ณตํ•œ๋‹ค. โญ๏ธ
8+
*/
9+
function getSum(a: number, b: number): number {
10+
while (b !== 0) {
11+
const carry = (a & b) << 1;
12+
a = a ^ b;
13+
b = carry;
14+
}
15+
return a;
16+
}

0 commit comments

Comments
ย (0)