注意从1开始索引,所以记得+1
代码:
1 int titleToNumber(string s) { 2 int res = 0; 3 4 for (int i = 0; i < s.length(); i++) { 5 res *= 26; 6 res += s[i] - 'A' + 1; 7 } 8 9 return res; 10 }
注意从1开始索引,所以记得+1
代码:
1 int titleToNumber(string s) { 2 int res = 0; 3 4 for (int i = 0; i < s.length(); i++) { 5 res *= 26; 6 res += s[i] - 'A' + 1; 7 } 8 9 return res; 10 }
转载于:https://www.cnblogs.com/boring09/p/4268484.html