Re: [闲聊] 每日leetcode

楼主: Furina (芙宁娜)   2025-01-12 00:08:57
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;
}
}
我好烂
作者: sustainer123 (caster)   2025-01-12 00:09:00
C 大神我几百年没写C 早忘光了
楼主: Furina (芙宁娜)   2025-01-12 00:17:00
你是py大神

Links booklink

Contact Us: admin [ a t ] ucptt.com