1 class Solution 2 { 3 public: 4 int titleToNumber(string s) 5 { 6 unordered_map<char,int> hash; 7 for(int i = 1;i <= 26;i ++) hash[‘A‘ + i - 1] = i; 8 int res = 0; 9 int n = s.size(); 10 for(int i = n - 1;i >= 0;i--) res += hash[s[i]] * pow(26,n - i - 1); 11 return res; 12 } 13 };
原文:https://www.cnblogs.com/yuhong1103/p/12627366.html