Created
August 16, 2017 09:55
-
-
Save luojiyin1987/72793e6a0dd48bf94a3ecd7f6ecf8845 to your computer and use it in GitHub Desktop.
Excel Sheet Column Number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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