371. 两整数之和
作者:互联网
不使用运算符 +
和 -
,计算两整数 a
、b
之和。
示例 1:
输入: a = 1, b = 2 输出: 3
示例 2:
输入: a = -2, b = 3 输出: 1
public class Solution371 {
public int getSum(int a, int b) {
while (b != 0) {
int brw = a & b;
a = a ^ b;
b = brw << 1;
}
return a;
}
public static void main(String[] args) {
Solution371 sol = new Solution371();
int a = 1, b = 2;
System.out.println(sol.getSum(a, b));
}
}
标签:示例,int,整数,brw,371,public,输入 来源: https://blog.csdn.net/allway2/article/details/113875887