mycode 90.39%
class Solution(object): def titleToNumber(self, s): """ :type s: str :rtype: int """ res = 0 for alpha in s: res = (ord(alpha) - 64) + res*26 return res
参考:
carry实际上就是十进制中的指数
class Solution(object): def titleToNumber(self, s): """ :type s: str :rtype: int """ def _map(ch): chn = ord(ch) assert chn >= ord('A') and chn <= ord('Z') return chn - ord('A') + 1 lens = len(s)-1 carry = 1 val = 0 while lens >=0: num = _map(s[lens])*carry val = val + num carry *= 26 lens -= 1 return val