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 fc5e450 commit 487873dCopy full SHA for 487873d
sum-of-two-integers/YeomChaeeun.ts
@@ -0,0 +1,17 @@
1
+/**
2
+ * 연산자 + 사용하지 않고 덧셈하기
3
+ * 알고리즘 복잡도
4
+ * - 시간 복잡도: O(logn) - 비트 수만큼 계산
5
+ * - 공간 복잡도: O(1)
6
+ * @param a
7
+ * @param b
8
+ */
9
+function getSum(a: number, b: number): number {
10
+ while(b !== 0) {
11
+ let carry = a & b; // and - 11 & 10 = 10
12
+ a = a ^ b; // xor - 11 ^ 10 = 01
13
+ b = carry << 1; // 100
14
+ }
15
+
16
+ return a
17
+}
0 commit comments