Posted on

Description

Submission

class Solution {
    int dfs(long long n) {
        if(n == 1) return 0;
        if(n % 2 == 0) return dfs(n>>1) + 1;
        return min(dfs(n-1), dfs(n+1)) + 1;
    }
public:
    int integerReplacement(int n) {
        return dfs(n);
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *