leetcode 371. Sum of Two Integers
异或其实是无进位加法,与取进位。
int getSum(int a, int b) { int ret = a ^ b; int carry = a & b; while (carry) { carry = carry << 1; int temp = carry; carry = carry & ret; ret = ret ^ temp; } return ret; }
【本文章出自博客园willaty,转载请注明作者出处,误差欢迎指出~】