0ms Golang solution


  • 0
    M
    func plusOne(digits []int) []int {
        for i := len(digits) - 1; i >= 0; i-- {
            digit := digits[i] + 1
            if digit == 10 {
                digits[i] = 0
            } else {
                digits[i] = digit
                return digits
            }
        }
        newDigits := []int{}
        newDigits = append(newDigits, 1)
        newDigits = append(newDigits, digits...)
        return newDigits
    }
    

Log in to reply
 

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