From c3274f76c1ccd9910150d4f002517548649c7e13 Mon Sep 17 00:00:00 2001 From: Claude Ni <49127719+ClaudeNi@users.noreply.github.com> Date: Sat, 1 Oct 2022 23:19:06 +0300 Subject: [PATCH] Create isPalindrome.py --- leetcode/python/isPalindrome.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 leetcode/python/isPalindrome.py diff --git a/leetcode/python/isPalindrome.py b/leetcode/python/isPalindrome.py new file mode 100644 index 0000000..89d1cea --- /dev/null +++ b/leetcode/python/isPalindrome.py @@ -0,0 +1,17 @@ +class Solution(object): + def isPalindrome(self, x): + """ + :type x: int + :rtype: bool + + Given an integer x, return true if x is palindrome integer. + An integer is a palindrome when it reads the same backward as forward. + """ + if x < 0: + return False + rev = list(str(x)) + rev.reverse() + rev = int("".join(rev)) + if x == rev: + return True + return False