Skip to content

Latest commit

 

History

History
18 lines (18 loc) · 652 Bytes

171. Excel Sheet Column Number.md

File metadata and controls

18 lines (18 loc) · 652 Bytes

思路

168题是将10进制转换为26进制,这题是将26进制转换为10进制.
例:将k进制数"abcd"转换为10进制数:res = d * k^0 + c * k^1 + b * k^2 + a * k^3.

C++

class Solution {
public:
    int titleToNumber(string s) {
        int res = 0, multiplier = 1;
        for(int i = s.size() - 1; i >= 0; i--){
            res += (int)(s[i] - 'A' + 1) * multiplier;
            multiplier *= 26;
        }
        return res;
    }
};