Palindrome Number — LeetCode

Soren Rood
Nov 28, 2020

Here is an image that explains this problem:

The first thing I noticed is that if a number is negative, it cannot be a palindrome since it has a negative sign. That case is easy to check, just validate that the input num > 0 or else return false.

The next operation that I performed was to convert the input integer into a string. Then you can reverse the string by doing the special python reverse trick:

x = 51
y = str(x)
reversed = y[::-1]

In the example above, reversed would print 15.

Here is the solution to the problem above in Python3. My submission was faster than 95% of other solutions:

--

--