Related to question Excel Sheet Column Title
Given a column title as appear in an Excel sheet, return its corresponding column number.
For example:
代码语言:javascript复制A -> 1
B -> 2
C -> 3
...
Z -> 26
AA -> 27
AB -> 28
代码语言:javascript复制二十六进制
public int titleToNumber(String s) {
int n = 0;
int p = 1;
for (int i = s.length() - 1; i >= 0; i--) {
n = (s.charAt(i) - 'A' 1) * p;
p *= 26;
}
return n;
}