Problem statement

https://binarysearch.com/problems/Palindromic-Integer/

Solution

Equal to leetcode Leetcode 0009 Palindrome Number

Complexity

Time complexity is just O(n), where n is length of number, space complexity is O(1).

Code

class Solution:
    def solve(self, x):
        if x < 0 or (x%10 == 0 and x != 0): return False
        
        rev = 0
        while x > rev:
            rev = rev*10 + x%10
            x //= 10

        return x == rev or x == rev//10