JZ48 不用加减乘除做加法
不用加减乘除做加法
https://www.nowcoder.com/practice/59ac416b4b944300b617d4f7f111b215?tpId=13&&tqId=11201&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking
牛逼
public class Solution { public int Add(int num1,int num2) { while(num2 != 0) { // 当进位为 0 时跳出 int c = (num1 & num2) << 1; // 先算当前进位 c = 进位 num1 ^= num2; // num1 = 非进位和 再算num1 num2 异或 num2 = c; // num2 = 进位 } return num1; } }