思路:
26进制
代码:
class Solution {
public:
int titleToNumber(string columnTitle) {
int n = columnTitle.size();
int res = 0;
typedef long long LL;
vector<LL> p(n + 1);
for(LL i = 0,q = 1;i < n;i++,q *= 26){
p[i] = q;
}
reverse(columnTitle.begin(),columnTitle.end());
for(int i = 0; i < n;i++){
res += (columnTitle[i] - 'A' + 1) * p[i];
}
return res;
}
};
评论区