Given a column title as appear in an Excel sheet, return its corresponding column number.
计算26进制数一样
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int titleToNumber(string s) { | |
int res = 0; | |
for (int i = 0; i<s.size(); i++) { | |
res = 26*res + s[i]-'A'+1; | |
} | |
return res; | |
} | |
}; |
No comments:
Post a Comment