Skip to content

Commit 2fb60c4

Browse files
committed
simplify
1 parent 928f7a3 commit 2fb60c4

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/sum_of_two_integers/main.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@ using namespace std;
1616
class Solution {
1717
public:
1818
int getSum(int a, int b) {
19-
int x = a, y = b;
20-
while (y != 0) {
21-
int xx = x ^ y;
22-
int yy = x & y;
23-
x = xx;
24-
y = yy << 1;
19+
while (b != 0) {
20+
int carry = a & b;
21+
a = a ^ b;
22+
b = carry << 1;
2523
}
26-
return x;
24+
return a;
2725
}
2826
};
2927

0 commit comments

Comments
 (0)