题目地址:这里
我的答案
class Solution(object):
def titleToNumber(self, s):
"""
:type s: str
:rtype: int
"""
s = s.upper()
total = 0
if s == '':
return total
for i,char in enumerate(s[::-1]):
temp = (26**i)*(ord(char) - ord('A') + 1)
total += temp
return total
难点在于计算字符对于数值的时候,原来想建立一个MAP来对应,但是这样太麻烦了,所以采用减法