题解 | #不用加减乘除做加法#
不用加减乘除做加法
https://www.nowcoder.com/practice/59ac416b4b944300b617d4f7f111b215
唔。。。建议具体思路看官方题解,不过我还是建议背下来
class Solution { public: int Add(int num1, int num2) { while (num2) { int sum = num1 ^ num2; int carry = (num1 & num2) << 1; num1 = sum; num2 = carry; } return num1; } };