Memory limit exceeded for this simple Python solution which works on my laptop


  • 0
    P
    def convertToTitle(self, n):
    	if(n % 26 == 0):
    		return (("A" * (n/26-1)) + "Z")
    	else:
    		return (("A" * int(n/26)) + chr(64 + n%26))

  • 0
    P

    Wish I could help, but I'm in the same boat. I've got a similar solution that gets the same error.


  • 1
    I

    I guess your solution is incorrect, please try the following test cases

    Your method
    convertToTile(52) = AZ which is correct

    but

    convertToTitle(53) = AAA is incorrect, the correct answer is BA

    Another few examples

    input your answer correct answer
    54 AAB BB
    701 AAAAAAAAAAAAAAAAAAAAAAAAAAY ZY
    702 AAAAAAAAAAAAAAAAAAAAAAAAAAZ ZZ

    Another test case OJ uses is 2147483647, your method hangs my desktop...anyway, the answer for this test case is 'FXSHRXW'

    Please note that the title after AZ is BA, not AAA
    Hope this helps.


Log in to reply
 

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