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 class Solution {
public int titleToNumber(String s) {
String ups=s.toUpperCase();
int result =0;
int deliver = 1;
char[] temp = ups.toCharArray();
for(int i=temp.length-1;i>=0;i--){
result +=CharToNumber(temp[i])*deliver;
deliver*=26;
}
return result;
}
public int CharToNumber(char c){
return (c-'A'+1);
}
}
来源:oschina
链接:https://my.oschina.net/u/1768500/blog/374696