class Solution:
def titleToNumber(self, s):
"""
:type s: str
:rtype: int
"""
#规律: sum(index(i)* 26^(n-i)) i=[1,n]
alphabte = ["A","B","C","D","E","F","G","H","I","J","K",
"L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
l = len(s)
out = 0
for i in range(l):
ind = alphabte.index(s[i]) + 1
out += ind * (26**(l-i-1))
return out
leetcode - 171 - Excel表列序号
最新推荐文章于 2024-02-06 20:39:22 发布