From fa30a90df8c3b4080fdebe48843001aac70e92c5 Mon Sep 17 00:00:00 2001 From: jabertuhin Date: Fri, 19 Nov 2021 14:21:46 +0600 Subject: [PATCH] Add second solution for 9. Palindrome Number. --- Algorithms/Easy/9_PalindromeNumber/SolutionOne.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Algorithms/Easy/9_PalindromeNumber/SolutionOne.py diff --git a/Algorithms/Easy/9_PalindromeNumber/SolutionOne.py b/Algorithms/Easy/9_PalindromeNumber/SolutionOne.py new file mode 100644 index 0000000..2f04d16 --- /dev/null +++ b/Algorithms/Easy/9_PalindromeNumber/SolutionOne.py @@ -0,0 +1,14 @@ +class Solution: + def isPalindrome(self, x: int) -> bool: + x_str = str(x) + left_idx = 0 + right_idx = len(x_str) - 1 + + while left_idx < right_idx: + if x_str[left_idx] != x_str[right_idx]: + return False + + left_idx += 1 + right_idx -= 1 + + return True \ No newline at end of file