LeetCode 171 Excel Sheet Column Number (Python)

Posted by 小明MaxMing on August 10, 2020

题目

Given a column title as appear in an Excel sheet, return its corresponding column number.

解题思路

相当于将26进制数转换成10进制数

代码

class Solution:
    def titleToNumber(self, s: str) -> int:
        res = 0
        for c in s:
            res = res * 26 + ord(c) - 64
        return res

视频讲解 YouTube<--欢迎点击订阅

视频讲解 bilibili<--欢迎点击订阅