Given a column title as appear in an Excel sheet, return its corresponding column number.
Thoughts
26进制转换. 只是每次要多加1因为它要的不是0~25而是1~26.
Code
class Solution {
public int titleToNumber(String s) {
int sum = 0;
for (int i = s.length() - 1; i >= 0; i--) {
char c = s.charAt(i);
sum += Math.pow(26, s.length() - 1 - i) * (c - 'A' + 1);
}
return sum;
}
}