266_Palindrome Permutation
Solution
class Solution(object):
def canPermutePalindrome(self, s):
"""
:type s: str
:rtype: bool
"""
# count frequency of each letter
dic = {}
for l in s:
if dic.get(l) is None:
dic[l] = 1
else:
dic[l] += 1
# compute how many of the frequencies are odd
# if more than one, return False immediately
module = 0
for i in dic.values():
module += i%2
if module > 1:
return False
return TrueLast updated