Share my c++ code


  • 0
    X

    int getSum(int a, int b) {

        int flag = 0;
    	int result = 0;
    	for(int i=0;i<32;i++)
    	{
    		int left = (a>>i) & 0x00000001;
    		int right = (b>>i) & 0x00000001;
    		int temp = left ^ right ^ flag;
    		if(flag == 1 && (left ==1 || right == 1) || (left ==1 && right == 1))
    		{
    			flag = 1;
    		}
    		else
    		{
    			flag = 0;
    		}
    
    		result = result ^ (temp << i);
    	
    	}
    	return result;
        }

Log in to reply
 

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