C++ Bit manipulation


  • 4
    M
    class Solution {
    public:
        int getSum(int a, int b) {
            while(b){
                int carry = a & b;
                a ^= b;
                b = carry << 1;
            }
            return a;
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.