9. Palindrome Number
  • Description
  • O(n)
    #!/usr/bin/python
    
    def isPalindrome(x):
        a = str(x)
    
        l = 0
        r = len(a)-1
    
        while l < r:
            if a[l] != a[r]:
                return False
            l += 1
            r -= 1
    
        return True
    
    if __name__ == '__main__':
        print isPalindrome(121)
        print isPalindrome(-121)
        print isPalindrome(10)