key: math
Runtime: 11 ms / beats 38.09%
No reference
class Solution {
public:
int titleToNumber(string s) {
int col = 0;
for(char i : s)
{
col = col * 26 + (i - 'A' + 1);
}
return col;
}
};
Update: no for range
Runtime: 8 ms / beats 43.62%
No reference
class Solution {
public:
int titleToNumber(string s) {
int col = 0;
for(int i = 0; i < s.size(); i++)
{
col = col * 26 + (s[i] - 'A' + 1);
}
return col;
}
};