https://leetcode.com/problems/sum-of-two-integers/description/
解题思路:
用and operation得到carrry, 用xor operation 得到a,然后对carry左移一位
代码:
class Solution {
public int getSum(int a, int b) {
if(a == 0) return b;
while(b != 0){
int carry = a & b;
a = a ^ b;
b = carry << 1;
}
return a;
}
}
网友评论