①⑦①
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
ANS:
class Solution
{
public:
int titleToNumber(string s)
{
int ans = 0;
for(int i = 0; i < s.size(); i ++)
{
ans = ans * 26 + (s.at(i) - 'A' + 1);
}
}
}
NOTES:
1.等同于26进制数,其他进制数与此相同;
2.直接减‘A’,如果记不住ASII码是多少(确实没记住,运行查了一下是65),避开不用。