题目
Related to question Excel Sheet Column Title
Given a column title as appear in an Excel sheet, return its corresponding column number.
答案
class Solution {
public int titleToNumber(String s) {
int t = 0;
int sum = 0;
for(int i = s.length() - 1; i >= 0; i--) {
char c = s.charAt(i);
int number = (int)c - (int)'A' + 1;
sum = sum + number * ((int)Math.pow(26, t++));
}
return sum;
}
}