Skip to content

Commit ad875ab

Browse files
authored
Update construct-k-palindrome-strings.cpp
1 parent 8f292bc commit ad875ab

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

C++/construct-k-palindrome-strings.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22
// Space: O(1)
33

44
class Solution {
5+
public:
6+
bool canConstruct(string s, int k) {
7+
bitset<26> odd;
8+
for (const auto& c : s) {
9+
odd.flip(c - 'a');
10+
}
11+
return odd.count() <= k && k <= s.length();
12+
}
13+
};
14+
15+
// Time: O(n)
16+
// Space: O(1)
17+
class Solution2 {
518
public:
619
bool canConstruct(string s, int k) {
720
const auto& count = counter(s);

0 commit comments

Comments
 (0)