Skip to content

Commit c06125c

Browse files
authored
Update minimum-operations-to-reduce-an-integer-to-0.cpp
1 parent ddd31c7 commit c06125c

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

C++/minimum-operations-to-reduce-an-integer-to-0.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ class Solution2 {
1818
int minOperations(int n) {
1919
int result = 0;
2020
while (n) {
21-
if ((n & 0b11) == 0b11) {
22-
++result;
23-
++n;
24-
} else {
25-
result += n & 1;
21+
if (!(n & 1)) {
2622
n >>= 1;
23+
continue;
2724
}
25+
++result;
26+
n += static_cast<int>(n & 0b10 == 0b10);
27+
n >>= 2;
2828
}
2929
return result;
3030
}

0 commit comments

Comments
 (0)