Skip to content

Commit 92bbc98

Browse files
committed
Anagram Palindrome
1 parent 58c724a commit 92bbc98

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Amazon/Problem#534.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""
2+
Given a string, determine whether any permutation of it is a palindrome.
3+
For example, carrace should return true, since it can be rearranged to form racecar,
4+
which is a palindrome. daily should return false, since there's no rearrangement that
5+
can form a palindrome.
6+
"""
7+
# Time Complexity: O(N), N -> length of s
8+
# Space Complexity: O(1)
9+
def palindromePermutation(s):
10+
alphabets = set()
11+
for c in s:
12+
if c in alphabets:
13+
alphabets.remove(c)
14+
else:
15+
alphabets.add(c)
16+
return len(alphabets) <= 1
17+

0 commit comments

Comments
 (0)