We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9d90baa commit 718ac71Copy full SHA for 718ac71
1 file changed
โsum-of-two-integers/Blossssom.tsโ
@@ -0,0 +1,28 @@
1
+/**
2
+ *
3
+ * @param a - ์ ์ a
4
+ * @param b - ์ ์ b
5
+ * @returns - ๋ํ๊ธฐ ์ฐ์ฐ ์์ด ๋ํ ๊ฐ ๋ฐํ
6
+ * @description
7
+ * - bit ์ฐ์ฐ์ด๊ตฌ๋! ์ถ์๋๋ฐ ๋นํธ๋ฅผ ์ ๋ค๋ฃฐ์ค ๋ชฐ๋ผ์ ai์ ๋์์ ๋ฐ์
8
+ */
9
+
10
+function getSum(a: number, b: number): number {
11
+ while (b !== 0) {
12
+ // ์ฌ๋ฆผ์ ๊ณ์ฐ : ๋๋ค 1์ธ ๋นํธ๋ฅผ AND ์ฐ์ฐ์ผ๋ก ์ฐพ์ ์ผ์ชฝ์ผ๋ก ๋ฐ (์ฌ๋ฆผ์๋๊น)
13
+ const carry = (a & b) << 1;
14
15
+ // XOR ์ฐ์ฐ์ผ๋ก ์ฌ๋ฆผ์๋ฅผ ์ ์ธํ ๋ง์ ๊ฐ ๋์ถ (1 | 0 ์ด๋ฏ๋ก)
16
+ a = a ^ b;
17
18
+ b = carry;
19
+ }
20
21
+ return a;
22
+}
23
24
+const a = 2;
25
+const b = 3;
26
+getSum(a, b);
27
28
0 commit comments