371. Sum of Two Integers - Medium
前往題目
思路
- 提取數字(用
XOR
) - 提取
carry
Code
class Solution {
public int getSum(int a, int b) {
// Until no carry
while (b != 0) {
int temp = (a & b) << 1;
a = a ^ b;
b = temp;
}
return a;
}
}
371. Sum of Two Integers - Medium
https://f88083.github.io/2024/03/18/371-Sum-of-Two-Integers-Medium/