问题描述:
Given a string columnTitle that represents the 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
…
根据字符串求对应的数字
class Solution {
public int titleToNumber(String columnTitle) {
int sum = 0;
for (int i=0; i<columnTitle.length(); i++){
sum = sum*26 + columnTitle.charAt(i)-'A'+1;
}
return sum;
}
}