Skip to content

Commit 833d40a

Browse files
committed
Added solution of sumOfTwoIntegers
1 parent 26d823b commit 833d40a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

sum-of-two-integers/nhistory.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
var getSum = function (a, b) {
2+
while (b !== 0) {
3+
if (b > 0) {
4+
a++;
5+
b--;
6+
} else {
7+
b++;
8+
a--;
9+
}
10+
}
11+
return a;
12+
};
13+
14+
// |b| is absolute value of b
15+
// TC: O(|b|)
16+
// SC: O(1)

0 commit comments

Comments
 (0)