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; } };
下一篇 初始操作系統中的虛擬內存(上)