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 c4f616e commit 67e7facCopy full SHA for 67e7fac
โsum-of-two-integers/soobing.tsโ
@@ -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