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字符串转数字
类似于进制转换,可以理解为26进制转10进制
class Solution { public: int titleToNumber(string s) { int res = 0 , base = 1; for(int i = s.size()⑴; i >= 0; i--) { res += base*(s[i]+1-'A'); base*=26; } return res; } };
下一篇 初始操作系统中的虚拟内存(上)