| 1 | |
| 2 | class Solution { |
| 3 | private static int addVal(int a, int b, int mask) { |
| 4 | if (b == 0) { |
| 5 | return a; |
| 6 | } |
| 7 | return addVal((a ^ b) & mask, ((a & b) << 1) & mask, mask); |
| 8 | } |
| 9 | |
| 10 | public static int getSum(int a, int b) { |
| 11 | int mask = 0xFFFFFFFF; |
| 12 | int val = addVal(a, b, mask); |
| 13 | if (val > Math.pow(2, 31)) { |
| 14 | return ~(val ^ mask); |
| 15 | } else { |
| 16 | return val; |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | public static void main(String[] args) { |
| 21 | System.out.println(getSum(-1, 1)); |
| 22 | } |
| 23 | } |
nothing calls this directly
no outgoing calls
no test coverage detected