Short 8ms C++ solution


  • 0
    R
    class Solution {
    public:
        int titleToNumber(string s) {
            int len = s.length() -1;
            int res = 0;
            for (int i= len, j=0 ; i>=0,j<=len; i--,j++){
                int temp = 1 + (s[i] - 'A');
                res += temp * (pow(26,j));
            }
            return res;
        }
    };

Log in to reply
 

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