JonnyF--Excel Sheet Column Title

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 

解题思路:

      这道题其实就是之前那个26进制转10进制的逆运算。只需要将字符转换后除26就好了。

class Solution:
    # @return a string
    def convertToTitle(self, num):
        res = ''
        while num:
            res = chr(ord('A') + (num-1) % 26) + res
            num = (num - 1) / 26
        return res
posted @ 2015-05-14 13:55  F-happy  阅读(80)  评论(0)    收藏  举报