A+B 问题
题目
源码
public class Solution {
/**
* @param a: An integer
* @param b: An integer
* @return: The sum of a and b
*/
public int aplusb(int a, int b) {
// write your code here
// int sum;
// int carry;
// while (b!=0){
// sum=a^b;
// carry=(a&b)<<1;
// a=sum;
// b=carry;
// }
// return a;
int sum;
int carry;
do{
sum=a^b;
carry=(a&b)<<1;
a=sum;
b=carry;
}while (carry!=0);
return sum;
}
}