题目描述:
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
...
Example 1:
Input: "A"
Output: 1
中文理解:将A-Z组成的字符串转换为整数表示。
解题思路:这个是1-26的26进制转换为10进制。
代码(java):
class Solution {
public int titleToNumber(String s) {
int res=0;
for(int i=0;i<s.length();i++){
res+=((int)(s.charAt(i)-'A')+1)*Math.pow(26,s.length()-i-1);
}
return res;
}
}