Skip to content

Commit

Permalink
is_palindrome implemented in two different ways (recursion and loopin…
Browse files Browse the repository at this point in the history
…g) in python
  • Loading branch information
Axel-Jacobsen authored and t2013anurag committed Oct 16, 2017
1 parent 31ffd11 commit bb4019e
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions is_palindrome/is_palindrome.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def is_palindrome_recursion(string):
if len(string) == 1 or len(string) == 0:
return True
elif string[0] == string[-1]:
return is_palindrome_recursion(string[1:-1])
else:
return False

def is_palindrome_looping(string):
while len(string) > 1:
if (string[0] == string[-1]):
string = string[1:-1]
else:
return False
return True

0 comments on commit bb4019e

Please sign in to comment.