From 93aacc352b57ece8273cb8d13993df3a724d440d Mon Sep 17 00:00:00 2001 From: Nir Binyamin Date: Fri, 3 May 2024 13:35:47 +0300 Subject: [PATCH] Adding solve for 1400 --- .../1400. Construct K Palindrome Strings.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Python/1400. Construct K Palindrome Strings.py diff --git a/Python/1400. Construct K Palindrome Strings.py b/Python/1400. Construct K Palindrome Strings.py new file mode 100644 index 00000000..f66fc0b9 --- /dev/null +++ b/Python/1400. Construct K Palindrome Strings.py @@ -0,0 +1,20 @@ +class Solution(object): + def canConstruct(self, s, k): + dict={char: 0 for char in "abcdefghijklmnopqrstuvwxyz"} + + if k==len(set(s)) or k== len(s): + return True + elif k>len(s): + return False + + for c in s: + dict[c]+=1 + + count=0 + for c in dict.keys(): + if dict[c]%2!=0: + count+=1 + + if count>k: + return False + return True