171. Excel Sheet Column Number

这个比较简单就是按公式就好了

class Solution(object):
    def titleToNumber(self, s):
        """
        :type s: str
        :rtype: int
        """
        dic = {}

        i = 1
        for x in range(ord('A'), ord('Z')+1):
            dic[chr(x)] = i
            i += 1
        if len(s) == 0:
            return 0
        res = 0
        for i in s:
            temp = dic[i]
            res = res * 26 + temp
        return res

你可能感兴趣的:(171. Excel Sheet Column Number)