Skip to content

Commit f0acddd

Browse files
EASY/src/easy/SumofTwoIntegers.java
1 parent f119d27 commit f0acddd

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

EASY/src/easy/SumofTwoIntegers.java

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package easy;
2+
3+
public class SumofTwoIntegers {
4+
//This post is very helpful: http://stackoverflow.com/questions/9070937/adding-two-numbers-without-operator-clarification
5+
//I also shared my solution here: https://discuss.leetcode.com/topic/49870/one-liner-with-detailed-explanation
6+
public int getSum(int a, int b) {
7+
if(b == 0) return a;
8+
int sum = a^b;
9+
int carry = (a&b) << 1;
10+
return getSum(sum, carry);
11+
}
12+
13+
}

0 commit comments

Comments
 (0)