Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions palindrome-pointers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Check if a string is a palindrome using the two-pointer approach

def pali(s):
left,right=0,len(s)-1

while left <= right:
if s[left]!=s[right]:
return False
left+=1
right-=1

return True

print(pali("tenet")) # True
print(pali("goat")) # False
print(pali("madam")) # True
print(pali("hello")) # False