leetpycode/medium/construct_k_palindrome_strings.py

12 lines
302 B
Python

# https://leetcode.com/problems/construct-k-palindrome-strings
from typing import Counter
class Solution:
def canConstruct(self, s: str, k: int) -> bool:
if len(s) < k:
return False
c = Counter(s)
odd = sum(v % 2 for v in c.values())
return odd <= k