作者oin1104 (是oin的說)
看板Marginalman
標題Re: [閒聊] 每日leetcode
時間Sat Jan 11 12:00:30 2025
題目
這字串能不能弄成K個回文字串
思路
一定要偶數才能弄到回文的兩邊
奇數只能放中間 所以不能超過k個
class Solution {
public:
bool canConstruct(string s, int k)
{
int n = s.size();
if(k == n )return 1;
if(k > n)return 0;
vector<int> save(26,0);
for(char k : s)save[k-'a'] ++;
int cnt = 0;
for(int i = 0 ; i < 26 ; i ++)
{
if(save[i]%2 == 1)cnt ++;
}
return cnt <= k;
}
};
--
邊版的小母雞 — fuckchicken
https://i.imgur.com/wglAuYR.jpg
https://i.imgur.com/jrYHfaa.jpeg
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 101.12.32.43 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1736568032.A.81A.html
→ LabMumi: 怎麼還在卷 01/11 12:00
推 mrsonic: 你寒假就這樣了 01/11 12:02