171. Excel Sheet Column Number
A -> 1
B -> 2
C -> 3
...
Z -> 26
AA -> 27
AB -> 28
...Input: "A"
Output: 1Input: "AB"
Output: 28Input: "ZY"
Output: 701解题要点:
Last updated
A -> 1
B -> 2
C -> 3
...
Z -> 26
AA -> 27
AB -> 28
...Input: "A"
Output: 1Input: "AB"
Output: 28Input: "ZY"
Output: 701Last updated
class Solution {
public int titleToNumber(String s) {
int res = 0;
int out = 1;
char[] c = s.toCharArray();
for(int i = c.length - 1; i >= 0; i--){
int temp = c[i] - 'A' + 1;
res = res + temp * out;
out *= 26;
}
return res;
}
}