Share my c++ code

  • 0
    class Solution {
        int getSum(int aa, int bb) {
            long long a=aa, b=bb;
    		int ext=0;
    		long ans=0;
    		for(int i=0;i<=31;i++){
    			int ai=(a & ((long long)1<<i))>0?1:0;
    			int bi=(b & ((long long)1<<i))>0?1:0;
    			int ci=ai^bi^ext;
    				ans=ans | ((long long)1<<i);
    			int di=32;
    			if(ai==0) di=di>>1;
    			else di=di<<1;
    			if(bi==0) di=di>>1;
    			else di=di<<1;
    			if(ext==0) di=di>>1;
    			else di=di<<1;
    			if(di>32) ext=1;
    			else ext=0;
    		return ans;

Log in to reply

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