luoheng
10/6/2019 - 3:12 PM

titleToNumber

func titleToNumber(s string) int {
    sum := 1
    times := make([]int, len(s))
    times[0] = 1
    for i := 1; i < len(s); i++ {
        times[i] = times[i-1] * 26
        sum += times[i]
    }
    for i := 0; i < len(s); i++ {
        sum += int(s[i]-'A') * times[len(s)-i-1]
    }
    return sum
}