1033. Broken Calculator
My accepted C++ solution to LeetCode problem 1033, Broken Calculator, running in 0ms.
- Difficulty: Medium
- C++
- Runtime 0ms
- Memory 7.9MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
C++
Accepted on LeetCode — runtime 0ms, memory 7.9MB, accepted 2025-12-27.
class Solution {
public:
int brokenCalc(int startValue, int target) {
int ops = 0;
while (target > startValue) {
if (target % 2 == 0) {
target /= 2;
} else {
target += 1;
}
ops++;
}
return ops + startValue - target;
}
};