Problem Description:
题目大意:
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
Solutions:
简单的26进制转化问题。
Code in C++:
class Solution {
public:
int titleToNumber(string s) {
int res=0;
int high=s.length()-1;
for(int i=0;i<s.length();i++)
res+=pow(26,high-i)*(s[i]-'A'+1);
return res;
}
};
近期评论