Related to question Excel Sheet Column Title
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
题目:一言蔽之,按照规则将字母转换成数字
思路:不罗嗦,参考之前博文的罗马数字转换
public int titleToNumber(String s) {
if(s==null||s.length()==0 ){
return 0;
}
int len = s.length();
int res = 0;
int digit = 1;
for(int i = len-1;i>=0;i--,digit*=26){
res = res + (s.charAt(i)-'A'+1)*digit;
}
return res;
}