【解题报告】【lintcode1】A + B Problem
题意
不适用任何数学运算实现A+B解答
使用位运算 异或运算可以当作加法,但是无法处理进位 需要使用按位与和左移来进行进位处理代码
class Solution { /* * param a: The first integer * param b: The second integer * return: The sum of a and b */ public int aplusb(int a, int b) { // write your code here, try to do it without arithmetic operators. while(b != 0){ int carry = a&b; a = a^b; b = carry<<1; } return a; } };