本质是26进制,注意每次+1.
class Solution { public: int titleToNumber(string s) { int size = s.size(); int num = 0; for (int i = 0; i < size; i++) { num = num * 26 + (s[i] - 'A' + 1); } return num; } };
本质是26进制,注意每次+1.
class Solution { public: int titleToNumber(string s) { int size = s.size(); int num = 0; for (int i = 0; i < size; i++) { num = num * 26 + (s[i] - 'A' + 1); } return num; } };