Skip to content

Palindrome Number

leetcode

link to string methods

essentially, if a pointer starts from start and another pointer starts from end, in each iteration, we can check if the characters at the two pointers are equal. If they are not equal, we can return false. If they are equal, we can move the pointers towards the center and repeat the process until the pointers meet in the middle.

Naive Approach

def isPalindrome(self, x: int) -> bool:
    s = str(x)
    start = 0
    end = len(s) - 1
    while start < end:
        if s[start] != s[end]:
            return False
        start+=1
        end-=1
    return True