1400. Construct K Palindrome Strings
Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 69% Topics: Hash Table, String, Greedy, Counting
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n)
# Space: O(1)
import collections
class Solution(object):
def canConstruct(self, s, k):
"""
:type s: str
:type k: int
:rtype: bool
"""
count = collections.Counter(s)
odd = sum(v%2 for v in count.itervalues())
return odd <= k <= len(s)
Solution from kamyu104/LeetCode-Solutions · MIT