Skip to content

Instantly share code, notes, and snippets.

@sreevidyavutukuru
Created July 6, 2017 19:37
Show Gist options
  • Save sreevidyavutukuru/d4df8037790492a05d6e08981de4ad6e to your computer and use it in GitHub Desktop.
Save sreevidyavutukuru/d4df8037790492a05d6e08981de4ad6e to your computer and use it in GitHub Desktop.
def palindrom(string1):
i = 0
j = len(string1) -1
flag = True
while i<len(string1)-1 and j >=0:
if string1[i] != string1[j]:
flag = False
break
else:
i += 1
j -= 1
return flag
def reverse(string1):
if len(string1) == 1:
return string1
else:
return string1[len(string1)-1] + reverse(string1[0:len(string1)-1])
#print reverse("abhdfg")
def palindrom_rec(string1):
flag = True
if len(string1) ==0 or len(string1) == 1:
return flag
elif string1[0] != string1[len(string1)-1]:
flag = False
return flag
else:
reverse(string1[1:len(string1)-1])
return flag
print palindrom_rec("gbcdcbg")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment