Python Solution without converting int to string


  • 0
    C
    class Solution(object):
        def isPalindrome(self, x):
            """
            :type x: int
            :rtype: bool
            """
            n=1
            ori=x
            while(x / 10 !=0):
                x=x/10
                n+=1
            print n
            while(n>0):
                tmp=ori %10
                if (tmp!=ori/(10**(n-1))):
                    return False
                ori-=(10**n)*(tmp)
                ori=ori/10
                n=n-2
            return True
    

Log in to reply
 

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