-
Notifications
You must be signed in to change notification settings - Fork 0
LC 0266 [E] Palindrome Permutation
Code with Senpai edited this page Oct 19, 2022
·
4 revisions
a palindrome can't have more than 1 char with odd frequency
class Solution:
def canPermutePalindrome(self, s: str) -> bool:
# return sum(v % 2 for v in collections.Counter(s).values()) < 2
c_to_freq = Counter(s)
odd = 0
for freq in c_to_freq.values():
if freq % 2:
odd += 1
if odd > 1:
return False
return True
footer