# 371. Sum of Two Integers

```
T: O(1)
S: O(1)
```

````java
```java
class Solution {
    public int getSum(int a, int b) {
        if (b == 0) {
            return a;
        }
        int sum = a ^ b;
        int carry = (a & b) << 1;
        return getSum(sum, carry);
    }
}

/*
sum -> like
1 + 0 = 1
0 + 1 = 1
0 + 0 = 0
1 + 1 = 0 -> 所以其實就是 xor 的操作 (相同 0,  不同 1)


carry ->
1 + 1 = 產生 carry -> 所以就是 & 操作, 然後左移一位(因為要進位)

如此就可以地歸來做...終止條件就是沒有 carry 時

return sum

T: O(1)
S: O(1)
*/
```
````
