题解 | #Excel列名称#

Excel列名称

http://www.nowcoder.com/practice/bb1e84f98b1640efbf2c6d3fc122bd04

n 对 26 取余 y = n % 26 得到当前的位数字符, 如果 y = 0 则当前位满26, 前一位 n // 26 应 - 1;

#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 
# @param n int整型 
# @return string字符串
#
class Solution:
    def ExcelTitle(self , n: int) -> str:
        # write code here
        chars = "ZABCDEFGHIJKLMNOPQRSTUVWXY"
        res = ""
        while n != 0:
            n, y = n // 26, n % 26
            res = chars[y] + res
            if y == 0:
                n = n - 1
        return res
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务