Skip to content

Instantly share code, notes, and snippets.

@luojiyin1987
Created August 16, 2017 09:55
Show Gist options
  • Save luojiyin1987/72793e6a0dd48bf94a3ecd7f6ecf8845 to your computer and use it in GitHub Desktop.
Save luojiyin1987/72793e6a0dd48bf94a3ecd7f6ecf8845 to your computer and use it in GitHub Desktop.
Excel Sheet Column Number
func titleToNumber(s string) int {
sum := 0
l := len(s) -1
for i :=len(s)-1; i>=0; i-- {
sum += int((s[i]-64)) * int(math.Pow(float64(26), float64(l-i) ))
}
return sum
}
//-----------------------------------------------------------------
func titleToNumber(s string) int {
bytes := []byte(s)
var ret int
for i := range bytes {
ret = 26 * ret + int(bytes[i] - 'A' + 1)
}
return ret
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment