171. Excel表列序号
https://leetcode-cn.com/problems/excel-sheet-column-number/
解法一:26进制
比168. Excel表列名称 简单,直接从低到高按幂次展开求和即可。
class Solution:
def titleToNumber(self, s: str) -> int:
count = 0 #幂次
res = 0 #累加和
for ch in s[::-1]:
res += (ord(ch) - 64) * 26 ** count
count += 1
return res
最后更新于