2023-11-20 15:30:57 +0000 UTC

Excel Sheet Column Number

Code

class Solution {
public:
    int titleToNumber(string columnTitle) {
        int ans{0};
        for (const char& ch : columnTitle) {
            ans = (ans * 26) + (ch - 'A') + 1;
        }
        return ans;
    }
};