C++ solution with comments!!

  • 0
    class Solution {
        int titleToNumber(string s) {
            int col=0;     // Base case
            for (int i=0; s[i]!=0; i++){    //iterate over the string
                col = col*26 + s[i] - 'A' + 1;   //(s[i] -'A' + 1) will return the corresponding value of s[i] column 
            return col;

Log in to reply

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