LeetCode-Solutions
LeetCode-Solutions copied to clipboard
Adding solve for 1400
Given a string s and an integer k, return true if you can use all the characters in s to construct k palindrome strings or false otherwise.
The Readme.md file has been updated.
I can tell this is your first pull request! Thank you I'm so honored. :tada::tada::tada: I'll take a look at it ASAP!
issue #484
from collections import Counter
def can_construct_palindrome(s, k):
# Count the frequency of each character in the string
char_count = Counter(s)
# Count the number of characters with odd frequency
odd_count = sum(count % 2 for count in char_count.values())
# If k is greater than or equal to the number of odd-count characters,
# it's possible to construct k palindromic strings
return k >= odd_count and k <= len(s)