Skip to content

Instantly share code, notes, and snippets.

@sumedhe
Last active July 9, 2016 11:02
Show Gist options
  • Select an option

  • Save sumedhe/4ef6f69348159b6a60ab625325757af6 to your computer and use it in GitHub Desktop.

Select an option

Save sumedhe/4ef6f69348159b6a60ab625325757af6 to your computer and use it in GitHub Desktop.
check whether a string is palindrome or not
class Stack:
def __init__(self):
self.items = []
def push(self, item):
self.items.append(item)
def pop(self):
return self.items.pop()
def peek(self):
return self.items[0]
def isEmpty(self):
return len(self.items) == 0
def isPalindrome(text):
s = Stack()
for c in text:
s.push(c)
revText = ""
while not s.isEmpty():
revText += s.pop()
return text == revText
##test
print(isPalindrome("abcba"))
print(isPalindrome("abbbc"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment