HTMLify

LeetCode - Construct K Palindrome Strings - Python
Views: 15 | Author: abh
class Solution:
    def canConstruct(self, s: str, k: int) -> bool:
        if len(s) < k: return False
        m = {}
        oc = 0
        for c in set(s):
            m[c] = s.count(c)
            oc += 1 if m[c]%2 else 0
            if oc > k:
                return False
        return True

Comments