lintcode a+b 问题
https://www.lintcode.com/prob...
def aplusb(self, a, b): # write your code here while True: a, b = a^b, (a&b)<<1 if a==0 or b == 0: return a or b
public int aplusb(int a ,int b) { // write your code here, try to do it without arithmetic operators.
while(true){ int x = a^b; //记录不进位数
int y = (a&b)<<1; //记录进位数
if(x==0){ return y;
} if (y==0){ return x;
}
a=x;
b=y;
} // while
}
偶然的你
宝慕林4294392
随时随地看视频慕课网APP
相关分类