leetcode 171. Excel表列序號

#思路就是26進制轉10進制,這樣一說是不是感覺很簡單了呢?
class Solution(object):
    def titleToNumber(self, s):
        """
        :type s: str
        :rtype: int
        """
        base=ord("A")-1
        count=0
        for S in s:
            count*=26
            count+=ord(S)-base
        return count



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章