Leetcode 1502 Solution

This article provides solution to leetcode question 1502 (construct-k-palindrome-strings)

https://leetcode.com/problems/construct-k-palindrome-strings

Solution

class Solution:
    def canConstruct(self, s: str, k: int) -> bool:
        m = collections.defaultdict(int)
        for ch in s:
            m[ch] += 1

        odd_cnt = 0
        for val in m.values():
            if val % 2 == 1:
                odd_cnt += 1

        return odd_cnt <= k and k <= len(s)