My C++ 0ms solution


  • 0
    E
    class Solution {
    public:
        int getSum(int a, int b) {
            int x, y, z = 0, result = 0;
    		for(int i = 1; i != 0; i <<= 1)
    		{
    			x = a&1;
    			y = b&1;
    			
    			int res = x^y^z;
    			z = (x&y)|(y&z)|(x&z);
    			
    			result >>= 1;
    			if(res)
    				result |= INT_MIN;
    			else
    				result &= INT_MAX;
    			
    			a >>= 1;
    			b >>= 1;
    		}
    		return result;
        }
    };
    

Log in to reply
 

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