Re: [閒聊] 每日leetcode

看板Marginalman作者 (是oin的說)時間11月前 (2025/01/11 12:00), 編輯推噓1(101)
留言2則, 2人參與, 11月前最新討論串1261/1554 (看更多)
題目 這字串能不能弄成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

01/11 12:00, 11月前 , 1F
怎麼還在卷
01/11 12:00, 1F

01/11 12:02, 11月前 , 2F
你寒假就這樣了
01/11 12:02, 2F
文章代碼(AID): #1dWUpWWQ (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1dWUpWWQ (Marginalman)