1400. Construct K Palindrome Strings
思路:
如果奇数个数的字母数大于k或字串长度小于k就false
C
bool canConstruct(char* s, int k) {
if (strlen(s) < k)
return 0;
if (strlen(s) == k)
return 1;
int count[200] = {0};
for (int i = 0; s[i] != '\0'; i++) {
count[s[i]]++;
}
int odd = 0;
for (int i = 97; i <= 122; i++) {
if (count[i] % 2 == 1) {
odd++;
}
}
if (odd <= k) {
return 1;
} else {
return 0;
}
}
我好烂