Easy to understand 8ms solution c++


  • 0
    C

    class Solution {
    public:
    int titleToNumber(string s) {

        int size =  (int)s.size();
        if(size < 0)
        {
            return 0;
        }
        int count = 0;
        for(int i = 0 ; i < size; i++)
        {
            int j = s[i] - 'A' + 1;
            int index  = size  - i - 1;
            if(index > 0)
            {
                j = j*pow(26,index);
            }
            count  = count + j;
        }
        return count;
    }
    

    };


Log in to reply
 

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