题目Given a column title as appear in an Excel sheet, return its corresponding column number.
这实际是26进制,跟问你12345是多少一样的。
12345=5*1+4*10+3*100+2*1000+1*10000
ABC=1*C+26*B+26*26*A
public class Solution {
static HashMap<Character,Integer>map=new HashMap<Character,Integer>();static {
char temp='A';
for(int i=0;i<26;i++){
map.put((char) (temp+i), i+1);
}
}
public static int titleToNumber(String s) {
int len=s.length();
int tmep=26;
int ret=0;
for(int i=len-1;i>=0;i--){
ret+=map.get(s.charAt(i))*Math.pow(tmep, len-1-i);
}
return ret;
}
}