Golang solution (0ms)


  • 0
    func convertToTitle(n int) string {
        result := []byte{}
        for n > 0 {
            result = append(result, 'A' + byte((n - 1) % 26))
            n = (n - 1) / 26
        }
        for i, j := 0, len(result) - 1; i < j; i, j = i + 1, j - 1 {
            result[i], result[j] = result[j], result[i]
        }
        return string(result)
    }
    

Log in to reply
 

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