0 ms golang solution. Simple


  • 0
    R
    func integerReplacement(n int) int {
        res := 0
            for n > 1 {
                if n%2 == 0 {
                    n /= 2
                } else if (n + 1) % 4 == 0 && n != 3 {
                    n++
                } else {
                    n--
                }
                res++
            }
            return res    
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.