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