public class Solution {
public int titleToNumber(String s) {
int len=s.length();
int sum=0;
int x=1;
len--;
while(len>=0){
sum+=(s.charAt(len)-64)*x;
x*=26;
len--;
}
return sum;
}
}
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 -> 28My solution: