public class Solution {
public int GetSum(int a, int b) {
if(a == 0) return b;
if(b == 0) return a;
int sum = 0;
while(b != 0){
sum = a ^ b; //get the sum without carry
b = (a & b) <<1; // get the carry
a = sum;
}
return sum;
}
}
Leetcode 371. Sum of Two Integers
最新推荐文章于 2024-08-09 18:00:00 发布