程式語言 - LeetCode - C++ - 171. Excel Sheet Column Number



題目:


解答:

class Solution {
public:
    int titleToNumber(string columnTitle) {
        int ans = 0;

        for (char ch : columnTitle) {
            ans = (ans * 26) + ((ch - 'A') + 1);
        }

        return ans;
    }
};