Skip to content
LC-0009 Easy LeetCode

9. Palindrome Number

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 59% Topics: Math
View full problem on LeetCode

Reading material

Reference solution (spoiler · python)
# Time:  O(1)
# Space: O(1)

class Solution(object):
    # @return a boolean
    def isPalindrome(self, x):
        if x < 0:
            return False
        copy, reverse = x, 0

        while copy:
            reverse *= 10
            reverse += copy % 10
            copy //= 10

        return x == reverse

Solution from kamyu104/LeetCode-Solutions · MIT