congr / world

2 stars 1 forks source link

LeetCode : 371. Sum of Two Integers #516

Closed congr closed 5 years ago

congr commented 5 years ago
class Solution {
    public int getSum(int a, int b) {
        while (b != 0) {
            int carry = a & b;
            a = a ^ b;
            b = carry << 1;
        }

        return a;
    }
}