-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpalindrome.py
More file actions
31 lines (28 loc) · 926 Bytes
/
palindrome.py
File metadata and controls
31 lines (28 loc) · 926 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# program should take in a string and return True if the string is a palindrome and False if not
# A palindrome is a word that is the same when it is reversed, such as madam, radar, kayak, or tacocat.
# Write code for algorithm 5 below
def is_palindrome(str):
if len(str) == 1 or len(str) == 0:
return True
else:
return (str[0] == str[-1]) and is_palindrome(str[1:-1])
print("is 'apple' a palindrome?")
print(is_palindrome('apple'))
print("is 'tacocat' a palindrome?")
print(is_palindrome('tacocat'))
# ------------------------------------------------------------
def solution(inputString):
count=[0]*256
for i in inputString:
count[ord(i)]+=1
odd=0
for i in range(0,256):
if(count[i]&1):
#print(count[i],chr(i))
odd+=1
# print(odd)
if(odd>1):
return False
return True
inputString = "aabb"
print(solution(inputString))