From 50b4d400aa139a6473dd6c2cc6d013d26a0366df Mon Sep 17 00:00:00 2001 From: Sanu Date: Thu, 28 Oct 2021 19:05:23 +0530 Subject: [PATCH 1/4] Added Solution of Q.no 0009 --- 0009/palindrome-number.py | 16 ++++++++++++++++ 0009/readme.md | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 0009/palindrome-number.py create mode 100644 0009/readme.md diff --git a/0009/palindrome-number.py b/0009/palindrome-number.py new file mode 100644 index 0000000..19a8ed1 --- /dev/null +++ b/0009/palindrome-number.py @@ -0,0 +1,16 @@ +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/) From f821d965a9f98aa97922ac9d458f000d67a38cbc Mon Sep 17 00:00:00 2001 From: Sanu Date: Thu, 28 Oct 2021 19:12:18 +0530 Subject: [PATCH 2/4] linting correctede --- 0009/palindrome-number.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/0009/palindrome-number.py b/0009/palindrome-number.py index 19a8ed1..e84f56a 100644 --- a/0009/palindrome-number.py +++ b/0009/palindrome-number.py @@ -1,16 +1,12 @@ class Solution: - def isPalindrome(self, x: int) -> bool: - + def isPalindrome(self, x: int) -> bool: temp = x rev = 0 - while( x > 0 ): - dig = x % 10 rev = rev * 10 + dig - x = x // 10 - + x = x // 10 if ( temp == rev ): return True - else: - return False + else: + return False \ No newline at end of file From 8179e2df1d92669d1ac67ff82bb44fc33b645368 Mon Sep 17 00:00:00 2001 From: Sanu Date: Thu, 28 Oct 2021 19:15:24 +0530 Subject: [PATCH 3/4] linting corrected --- 0009/palindrome-number.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/0009/palindrome-number.py b/0009/palindrome-number.py index e84f56a..b22b871 100644 --- a/0009/palindrome-number.py +++ b/0009/palindrome-number.py @@ -1,12 +1,12 @@ class Solution: - def isPalindrome(self, x: int) -> bool: + def isPalindrome(self, x: int) -> bool: temp = x rev = 0 - while( x > 0 ): - dig = x % 10 - rev = rev * 10 + dig + while(x > 0): + dig = x % 10 + rev = rev * 10 + dig x = x // 10 - if ( temp == rev ): + if(temp == rev): return True - else: + else: return False \ No newline at end of file From e000e8d230248876e7bc9146c49984c0918cd7ae Mon Sep 17 00:00:00 2001 From: Sanu Date: Thu, 28 Oct 2021 19:17:13 +0530 Subject: [PATCH 4/4] linting corrected --- 0009/palindrome-number.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/0009/palindrome-number.py b/0009/palindrome-number.py index b22b871..2b3a7a9 100644 --- a/0009/palindrome-number.py +++ b/0009/palindrome-number.py @@ -5,8 +5,8 @@ def isPalindrome(self, x: int) -> bool: while(x > 0): dig = x % 10 rev = rev * 10 + dig - x = x // 10 + x = x // 10 if(temp == rev): return True else: - return False \ No newline at end of file + return False