【题目描述】
Related to question Excel Sheet Column Title
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 【思路】
就是把 Excel Sheet Column Title的思路反过来。
【代码】
class Solution {
public:
int titleToNumber(string s) {
int len=s.length();
int ans=0;
int cnt=1;
for(int i=len-1;i>=0;i--){
ans+=(s[i]-'A'+1)*cnt;
cnt=cnt*26;
}
return ans;
}
};
8634




被折叠的 条评论
为什么被折叠?



