Leetcode: Palindrome Number

Rachit Gupta
1 min readDec 23, 2016

--

This is a simple extension of the reverse integer problem. We can compare the reversed integer with the given integer to check for palindrome

Remarks:

  1. O(n) space complexity, for storing a string of size n
  2. O(n) time complexity, for reversing string of size n
class Solution(object):
def isPalindrome(self, x):
"""
:type x: int
:rtype: bool
"""
if x < 0:
return False
return x == int(str(x)[::-1])
def isPalindrome(self, x):
return False if x < 0 else x == int(str(x)[::-1])
def isPalindrome(self, x):
if x < 0:
return False
return str(x) == str(x)[::-1]

--

--