My 3ms C++ Solution


  • 0
    H

    class Solution {
    public:
    int titleToNumber(string s) {
    int res=0;
    if(s.size()==1) return (s[0]-'A'+1);
    for(int i=0;i<s.size();i++){
    int n=s[i]-'A'+1;
    int w=s.size()-i-1;
    res+=pow(26,w)*n;
    }
    return res;
    }
    };


Log in to reply
 

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