diff --git a/0009/palindrome-number.py b/0009/palindrome-number.py new file mode 100644 index 0000000..2b3a7a9 --- /dev/null +++ b/0009/palindrome-number.py @@ -0,0 +1,12 @@ +class Solution: + def isPalindrome(self, x: int) -> bool: + temp = x + rev = 0 + while(x > 0): + dig = x % 10 + rev = rev * 10 + dig + x = x // 10 + if(temp == rev): + return True + else: + return False diff --git a/0009/readme.md b/0009/readme.md new file mode 100644 index 0000000..08b94a9 --- /dev/null +++ b/0009/readme.md @@ -0,0 +1,39 @@ +# 9. Palindrome Number + +Given an integer x, return true if x is palindrome integer. + +An integer is a palindrome when it reads the same backward as forward. + +For example, 121 is palindrome while 123 is not. + +### Examples: + +Example 1: + + Input: x = 121 + Output: true + +Example 2: + + Input: x = -121 + Output: false + Explanation: From left to right, it reads -121. From right to left, it becomes 121-. + Therefore it is not a palindrome. + +Example 3: + + Input: x = 10 + Output: false + Explanation: Reads 01 from right to left. + Therefore it is not a palindrome. + +Example 4: + + Input: x = -101 + Output: false + +## Constraints: + + -231 <= x <= 231 - 1 + +#### Question link : [9_Palindrome_Number](https://leetcode.com/problems/palindrome-number/)