[leetcode: Python]171. Excel Sheet Column Number

来源:互联网 发布:微信公众号小游戏源码 编辑:程序博客网 时间:2024/06/09 07:24

题目:
Related to question Excel Sheet Column Title

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

For example:

    A -> 1    B -> 2    C -> 3    ...    Z -> 26    AA -> 27    AB -> 28 

同样可以用26进制转化为十进制的思想。

方法一:性能52ms

class Solution(object):    def titleToNumber(self, s):        """        :type s: str        :rtype: int        """        n = 0        if len(s) == 0:            return 0        for i in range(0, len(s)):            n += pow(26, len(s)-i-1)*(ord(s[i])-64)        return n
0 0
原创粉丝点击