HTMLify
is_palindrome.py
Views: 466 | Author: abh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #Check the given string, number or list is palindrome or not. def is_palindrome(n: int) -> bool: r = 0 t = n while n > 0: r = r * 10 + n % 10 n //= 10 return r == t def is_palindrome(s: str) -> bool: return s == s[::-1] def is_palindrome(s: list) -> bool: s = list(s) return s == s[::-1] def is_palindrome(s) -> bool: left = 0 right = len(s) - 1 while left < right: if s[left] != s[right]: return False left += 1 right -= 1 return True def is_palindrome(s) -> bool: s = str(s) return s == s[::-1] |