Neat python solution


  • 0
    J
    class Solution(object):
    def convertToTitle(self, n):
        """
        :type n: int
        :rtype: str
        """
        c=['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
        s=[]
        while n>0:
            a=(n-1)%26
            s.append(c[a])
            n=(n-1)/26
        return ''.join(s[::-1])

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.