leetcode_168. Excel表列名称

给定一个正整数,返回它在 Excel 表中相对应的列名称。

例如,

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

输入: 1
输出: "A"
示例 2:

输入: 28
输出: "AB"
示例 3:

输入: 701
输出: "ZY"

来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/excel-sheet-column-title
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
class Solution:
    def convertToTitle(self, n: int) -> str:
        ls=[]
        while(n>0):
            t=n%26
            if t==0:
                t=26
                n-=1
            ls.append(chr(ord('A')+t-1))
            n=n//26
        s=''
        while ls:
            s+=ls.pop()
        return s
posted @ 2020-12-02 16:31  hqzxwm  阅读(63)  评论(0编辑  收藏  举报