Re: [閒聊] 每日leetcode

看板Marginalman作者 (dont)時間11月前 (2025/01/11 17:07), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1262/1554 (看更多)
1400. Construct K Palindrome Strings ## 思路 1.字串長度必須要大於K 2.回文: AABB / ABA 計算字元的奇偶個數 最多只能有K個字元是奇數個 ## CODE ```CPP class Solution { public: bool canConstruct(string s, int k) { if (k > s.length()) return false; vector<int> count(26, 0); for (char& ch: s) { ++count[ch-'a']; } for (int i=0; i<26; ++i) { k -= (count[i] & 1); } return k >= 0; } }; ``` -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 194.195.89.62 (日本) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1736586438.A.801.html
文章代碼(AID): #1dWZJ6W1 (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1dWZJ6W1 (Marginalman)