Skip to content

Commit ee6b125

Browse files
committed
Time: 0 ms (100%), Space: 6.7 MB (12.53%) - LeetHub
1 parent 4caaf68 commit ee6b125

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public:
3+
int minOperations(int n) {
4+
int ans = 0;
5+
while(n) {
6+
int pw = round(log(n) / log(2));
7+
n = abs(n - pow(2, pw));
8+
ans++;
9+
}
10+
return ans;
11+
}
12+
};

0 commit comments

Comments
 (0)