Re: [閒聊] 每日leetcode
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;
}
}
我好爛
--
芙芙搖 https://i.imgur.com/MaRqFO6.gif





--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 223.141.220.186 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1736611740.A.94B.html
→
01/12 00:09,
11月前
, 1F
01/12 00:09, 1F
你才是大神
※ 編輯: Furina (223.141.220.186 臺灣), 01/12/2025 00:12:43
推
01/12 00:14,
11月前
, 2F
01/12 00:14, 2F
→
01/12 00:17,
11月前
, 3F
01/12 00:17, 3F
討論串 (同標題文章)
完整討論串 (本文為第 1265 之 1554 篇):