问题:app
Related to question Excel Sheet Column Titleexcel
Given a column title as appear in an Excel sheet, return its corresponding column number.code
For example:leetcode
A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28
解决:get
① 能够当作26进制数的运算来理解。it
public class Solution {//2ms
public int titleToNumber(String s) {
int res = 0;
for (int i = 0;i < s.length();i ++ ) {
int tmp = ((s.charAt(i) - 'A') + 1);
res = res * 26 + tmp;
}
return res;
}
}io