There is a one line solution in C++


  • 0
    J
    class Solution {
    public:
        int titleToNumber(string s) {
            return s.size() == 1 ? s[0] - 'A' + 1 : 26 * titleToNumber(s.substr(0, s.size() - 1)) + (s[s.size() - 1]) - 'A' + 1;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.