题解 | #不用加减乘除做加法#
不用加减乘除做加法
http://www.nowcoder.com/practice/59ac416b4b944300b617d4f7f111b215
class Solution
{
public int Add(int num1, int num2)
{
while(carry!=0){
int tmp = sum ^ carry;
carry = (sum & carry)<<1;
sum = tmp;
}
return sum;
}
}
{
public int Add(int num1, int num2)
{
// write code here
int sum = num1;
int carry = num2;while(carry!=0){
int tmp = sum ^ carry;
carry = (sum & carry)<<1;
sum = tmp;
}
return sum;
}
}