Python code without new variable & function


  • 0
    C

    "Without extra space" makes this question fun.

    Sorry for the chunky code.

    class Solution(object):
        def isPalindrome(self, x):
    
            if (x!=abs(x)): return(False)
            while(x>=0):
                if (x<10): return(True)
                if(((x-(x%10)*10**(len(str(x))-1))>0)and((x-(x%10)*10**(len(str(x))-1))<10**(len(str(x))-1))):
                    if((x-(x%10)*10**(len(str(x))-1))<10**(len(str(x))-2)):
                        if((x//10)%(10**(len(str(x))-2-len(str(x//10-(x%10)*10**(len(str(x))-2)))))==0):
                            x=(x-(x%10)*10**(len(str(x))-1))//(10**(len(str(x))-1-len(str(x//10-(x%10)*10**(len(str(x))-2)))))
                        else:
                            return(False)
                    else:
                        x-=(x%10)*10**(len(str(x))-1)
                        x=x//10
                else:
                    return(False)
            return(True);
    

Log in to reply
 

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