3 lines in python (compare reverse string)


  • 0
    I

    passed solution: compare if the value equals to the reversed value(by using string):
    step1: convert int to string, this is the code: x
    step2: compare, this is the code: int(x[::-1]) == x

    """
    class Solution(object):
    def isPalindrome(self, x):
    if x < 0:
    return False
    return int(x[::-1]) == x
    """


Log in to reply
 

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