Skip to content

Commit 81e1e53

Browse files
authored
Create 1400. Construct K Palindrome Strings (#687)
2 parents 59e38a3 + 89f20f6 commit 81e1e53

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

1400. Construct K Palindrome Strings

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public:
3+
bool canConstruct(string s, int k) {
4+
if (k > s.length()) return false;
5+
int charCount[26] = {0};
6+
for (char c : s) {
7+
charCount[c - 'a']++;
8+
}
9+
int oddCount = 0;
10+
for (int i = 0; i < 26; i++) {
11+
if (charCount[i] % 2 == 1) oddCount++;
12+
}
13+
return oddCount <= k;
14+
}
15+
};

0 commit comments

Comments
 (0)