Sharing my really simple and straightforward solution


  • 2
    Z
    int titleToNumber(string s) {
        int result = 0;
        for(int i = 0; i < s.length(); i++){
            result += (s[i] - 'A' + 1) * pow(26, s.length() - 1 -i);
        }
        return result;
    }
    

    The basic idea is simple: every digit has a weight.


Log in to reply
 

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