A 12ms, 4 line C++ solution for titleToNumber


  • 1
    M

    iterative addition:

    int titleToNumber(string s) {
    	int res = 0;
    	for (auto c : s)
    		res = 26 * res + (c - 'A' + 1);
    	return res;
    }

Log in to reply
 

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