171. Excel表列序号

题目
很简单,就是从左到右遍历s。需要注意ord()函数的使用。
class Solution:
def titleToNumber(self, s: str) -> int:
ans = 0
for c in s:
ans *= 26
ans += ord(c) - ord('A') + 1
return ans
很简单,就是从左到右遍历s。需要注意ord()函数的使用。
class Solution:
def titleToNumber(self, s: str) -> int:
ans = 0
for c in s:
ans *= 26
ans += ord(c) - ord('A') + 1
return ans