MCPcopy Create free account
hub / github.com/Sugapriyan-P-K/blind75 / Solution

Class Solution

Binary_bitManipulation/11sumOfTwoInteger/sumOfTwoInt.java:2–23  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1
2class 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}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected