171.go 230 B

12345678910111213
  1. package main
  2. func titleToNumber(s string) int {
  3. res := 0
  4. for base, i := 1, len(s)-1; i >= 0; base, i = base*26, i-1 {
  5. res += base * int(s[i]-'A'+1)
  6. }
  7. return res
  8. }
  9. // func main() {
  10. // fmt.Println(titleToNumber("WV"))
  11. // }