From 89f20f689ac7619005ee6b06dde03f82bc30dca1 Mon Sep 17 00:00:00 2001 From: chayan das <110921638+Chayandas07@users.noreply.github.com> Date: Sat, 11 Jan 2025 23:58:31 +0530 Subject: [PATCH] Create 1400. Construct K Palindrome Strings --- 1400. Construct K Palindrome Strings | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 1400. Construct K Palindrome Strings diff --git a/1400. Construct K Palindrome Strings b/1400. Construct K Palindrome Strings new file mode 100644 index 0000000..7581059 --- /dev/null +++ b/1400. Construct K Palindrome Strings @@ -0,0 +1,15 @@ +class Solution { +public: + bool canConstruct(string s, int k) { + if (k > s.length()) return false; + int charCount[26] = {0}; + for (char c : s) { + charCount[c - 'a']++; + } + int oddCount = 0; + for (int i = 0; i < 26; i++) { + if (charCount[i] % 2 == 1) oddCount++; + } + return oddCount <= k; + } +};