Advertisement
AliaksandrLet

Palindrome

May 14th, 2022
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. def isPalindrome(string):
  2.     rev_string = string[::-1]
  3.     return string == rev_string
  4.  
  5. def isPalindrome2(string):
  6.     rev_string = ''.join(reversed(string))
  7.     return string == rev_string
  8.  
  9. def isPalindrome3(string):
  10.     left, right = 0, len(string) - 1
  11.     while right >= left:
  12.         if not string[left] == string[right]:
  13.             return False
  14.         left += 1
  15.         right -= 1
  16.     return True
  17.  
  18. print(isPalindrome('redrum murder'))
  19. print(isPalindrome2('redrum murder'))
  20. print(isPalindrome3('redrum murder'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement