https://leetcode.com/problems/excel-sheet-column-number/
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这道题跟前一道题是对应的,这里更简单,就是求出每一位对应的值,然后按26进制算就行了。
public int titleToNumber(String s) {
int val = 0;
for(int i=0; i<s.length(); i++){
int current = s.charAt(i) - 'A'+1;
val = val*26+current;
}
return val;
}