题目:将excel字母转成数字
分析:肉眼可见就是将26进制转成10进制,没什么好分析的。
答案:
class Solution {
public:
int titleToNumber(string s)
{
int ans = 0;
for (int i = 0; i < s.length(); i ++)
{
int currentDigit = s[i] - 'A' + 1;
ans *= 26;
ans += currentDigit;
}
return ans;
}
};