Integer Replacement LeetCode solution in C++

1
class Solution {
2
public:
3
int integerReplacement(int n) {
4
return helper(n);
5
}
6

7
int helper(long n) {
8
if (n == 1) return 0;
9

10
if (n % 2) return 1 + min(helper(n - 1), helper(n + 1));
11

12
return 1 + helper(n / 2);
13
}
14
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0