(LeetCode)Excel Sheet Column Title --- Excel页码映射

来源:互联网 发布:java字符串替换某一位 编辑:程序博客网 时间:2024/06/05 07:44

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

For example:

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

Credits:

Special thanks to @ifanchu for adding this problem and creating all test cases.


解题分析:

这个题目和这个很像,都是利用ascii码,进行转换的,

http://blog.csdn.net/u012965373/article/details/52754538

此处是将数字转换为字符,由于先求出来的是最后面的,因此求出后要先反转,再返回。


# -*- coding:utf-8 -*-__author__ = 'jiuzhang'class Solution(object):    def convertToTitle(self, n):        res = ''        while n > 0:            tmp = n            n = (tmp - 1)/26            res += chr(65 + (tmp - 1) % 26)        return res[::-1]


0 0
原创粉丝点击