What is wrong with my python code? HELP!!


  • 0
    F
    class Solution(object):
        def convertToTitle(self, n):
            """
            :type n: int
            :rtype: str
            """
            if n<=0:
                return None
            bound=ord('A')
            dict={}
            for i in range(1, 27, 1):
                dict[i]=chr(i+bound-1)
            rst=""
            while n>0:
                rst+=dict[n%26]
                n/=26
            return rst[::-1]

  • 0
    J

    Try test-case: 1.

    dict[0] does not exist.


Log in to reply
 

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