您的位置:首页 > 其它

lintcode A+B问题

2018-03-10 19:46 162 查看

A + B 问题

给出两个整数a和b, 求他们的和, 但不能使用 + 等数学运算符。

代码

public class Solution {
public int aplusb(int a, int b) {
if(a==0)return b;
if(b==0)return a;
int x1 = a^b;
int x2 = (a&b)<<1;
return aplusb(x1,x2);
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: