Skip to content

Commit 9093505

Browse files
committed
feat: sum-of-two-integers
1 parent cddf0cf commit 9093505

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

sum-of-two-integers/minji-go.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* <a href="https://leetcode.com/problems/sum-of-two-integers/">week9-4. sum-of-two-integers</a>
3+
* <li>Description: Given two integers a and b, return the sum of the two integers without using the operators + and -.</li>
4+
* <li>Topics: Math, Bit Manipulation </li>
5+
* <li>Time Complexity: O(1), Runtime 0ms </li>
6+
* <li>Space Complexity: O(1), Memory 40.51MB </li>
7+
*/
8+
class Solution {
9+
public int getSum(int a, int b) {
10+
while (b != 0) {
11+
int tmp = (a & b) << 1;
12+
a = (a ^ b);
13+
b = tmp;
14+
}
15+
return a;
16+
}
17+
}

0 commit comments

Comments
 (0)