@author: ZZQ
@software: PyCharm
@file: leetcode171_Excel表列序号.py
@time: 2018/11/22 15:29
要求:
给定一个Excel表格中的列名称,返回其相应的列序号。
例如,
    A -> 1
    B -> 2
    C -> 3
    ...
    Z -> 26
    AA -> 27
    AB -> 28
    ...
示例 1:
    输入: "A"
    输出: 1
示例 2:
    输入: "AB"
    输出: 28
示例 3:
    输入: "ZY"
    输出: 701
class Solution():
    def __init__(self):
        pass

    def rule(self, value):
        return ord(value)-ord('A')+1

    def titleToNumber(self, s):
        """
        :type s: str
        :rtype: int
        """
        s_len = len(s)
        ans = 0
        for i in range(s_len):
            ans += pow(26,(s_len-i-1))*self.rule(s[i])
        return ans

相关文章:

  • 2021-11-29
  • 2022-12-23
  • 2021-12-10
  • 2021-07-27
  • 2022-01-02
  • 2022-12-23
  • 2022-12-23
  • 2021-11-05
猜你喜欢
  • 2021-12-20
  • 2022-01-29
  • 2021-12-29
  • 2021-09-18
  • 2022-12-23
  • 2021-07-15
相关资源
相似解决方案