题目:
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解答:
与stringToInt类似,只是mode值为26了;
代码:
public class Solution {
public int titleToNumber(String s) {
int ret = 0;
if (s != null && !s.isEmpty()) {
for (char c : s.toCharArray()) {
ret = ret * 26 + c + 1 - 'A';
}
}
return ret;
}
}