8ms c++ solution


  • 0
    P
    int titleToNumber(string s) 
    {
        int number = 0, len = s.length();
        for(int i = 0, p = len - 1; i < len; ++i, --p)
        {
            char letter = s[i];
            //int val = (letter >= 'A' && letter <= 'Z') ? letter - 'A' : letter - 'a'; // if you want to support lowercase
            int val = letter - 'A';
            number += (val+1) * pow(26, p);
        }
        return number;
    }

Log in to reply
 

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