LeetCode-Solutions icon indicating copy to clipboard operation
LeetCode-Solutions copied to clipboard

problem number 1400 - Python

Open NirBinyamin8 opened this issue 1 year ago • 2 comments

Greetings,

I did not find a solution to problem number 1400 in the Python language - that's why I added a solution to this problem, in addition I updated the readme file.

NirBinyamin8 avatar May 03 '24 10:05 NirBinyamin8

Thanks for helping us improve and opening your first issue here! Don't forget to give us a 🌟 to support us.

While you're waiting, I just wanted to make sure you've had a chance to look at our Readme and Pull Request Guidelines.

welcome[bot] avatar May 03 '24 10:05 welcome[bot]

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)

bitsgorilla avatar Jun 12 '24 10:06 bitsgorilla