Construct K Palindrome Strings LeetCode solution in Python

1
from collections import Counter
2

3

4
class Solution:
5
def canConstruct(self, s: str, k: int) -> bool:
6
if k > len(s):
7
return False
8
h = Counter(s)
9
countOdd = 0
10
for value in h.values():
11
if value % 2:
12
countOdd += 1
13
if countOdd > k:
14
return False
15
return True

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0