Related to questionExcel 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
Credits:
Special thanks to@tsfor adding this problem and creating all test cases.
class Solution {
public int titleToNumber(String s) {
int ans = 0;
for (int i = 0; i < s.length(); i++){
int num = s.charAt(i) - 'A';
num++;
ans = ans * 26 + num;
}
return ans;
}
}