LC 0266 [E] Palindrome Permutation - ALawliet/algorithms GitHub Wiki

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