自己写的
class Solution { public: int Add(int num1, int num2) { int a = num1 ^ num2; int b = (num1 & num2) << 1; while(b){ int c = a ^ b; int d = (a & b) << 1; a = c; b = d; } return a; } };
注意:做位运算的与是&,不是&&
自己写的
class Solution { public: int Add(int num1, int num2) { int a = num1 ^ num2; int b = (num1 & num2) << 1; while(b){ int c = a ^ b; int d = (a & b) << 1; a = c; b = d; } return a; } };
注意:做位运算的与是&,不是&&