Broken Calculator LeetCode solution in C++

1
class Solution {
2
public:
3
int brokenCalc(int startValue, int target) {
4
int result = 0;
5
while (target > startValue) {
6
result++;
7
if (target % 2 == 0)
8
target = target / 2;
9
else
10
target += 1;
11
}
12
result = result + (startValue - target);
13
return result;
14
}
15
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0