Leetcode Palindrome Number problem solution in Python programming

In the Leetcode Palindrome Number problem solution in Python programming Given an integer x, return true if x is a palindrome, and false otherwise.

Leetcode Palindrome Number problem solution in Python programming

import math

class Solution(object):
    def isPalindrome(self, x):
        if x < 0:
            return False
        
        digits = 1
        while x // digits >= 10:
            digits *= 10
            
        while x > 0:
            last = x % 10
            first = x // digits
            
            if last != first:
                return False
            
            x %= digits
            x //= 10
            
            digits //= 100
        
        return True

Also read,

By Neha Singhal

Hi, my name is Neha singhal a software engineer and coder by profession. I like to solve coding problems that give me the power to write posts for this site.

Leave a Reply

Your email address will not be published. Required fields are marked *