C++ one-liner without explicit loop


  • 0
    M

    This may have already been presented in an earlier post ...

    class Solution {
    public:
        int titleToNumber(const string& s)
        {
            auto col = accumulate(
                begin(s), end(s), 0,
                [](int total, char ch)
                {
                    return (26 * total) + (1 + ch - 'A');
                });
    
            return col;
        }
    };
    

Log in to reply
 

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