题目:
Given a column title as appear in an Excel sheet, return its corresponding column number.
思路:
很简单,直接看代码就好。
代码实现:
class Solution {
public:
int char2Int(char c){
return c-'A'+1;
}
int titleToNumber(string s) {
int sum = char2Int(s[0]);
for (int i = 1; i < s.size(); ++i){
sum = sum * 26 + char2Int(s[i]);
}
return sum;
}
};