Leetcode - Excel Sheet Column Number
https://leetcode.com/problems/excel-sheet-column-number/
Given a column title as appear in an Excel sheet, return its corresponding column number.
For example:
A -> 1
B -> 2
C -> 3
...
Z -> 26
AA -> 27
AB -> 28
...
Example 1:
Input: "A" Output: 1
func titleToNumber(s string) int {
count := 1
result := 0
for i := len(s)-1; i >= 0; i-- {
num := int(s[i] - 'A') + 1
result += num * count
count *= 26
}
return result
}
评论 (0)