Problem
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
Solution
class Solution {
public int titleToNumber(String s) {
int n = s.length();
int sum = 0, base = 1;
for (int i = n-1; i >= 0; i--) {
sum += (s.charAt(i) - 'A' + 1) * base;
base *= 26;
}
return sum;
}
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。