Re: [閒聊] 每日leetcode

看板Marginalman作者 (dont)時間11月前 (2025/01/13 19:24), 編輯推噓2(200)
留言2則, 2人參與, 11月前最新討論串1272/1554 (看更多)
3223. Minimum Length of String After Operations ## 思路 先計算每個字元的出現次數 AAAAA --> AAA -> A AAAA --> AA 如果奇數就+1, 偶數+2 ## Code ```cpp class Solution { public: int minimumLength(string s) { int res = 0; vector<int> count(26, 0); for (char& ch: s) { count[ch-'a']++; } for (int i=0; i<26; ++i) { if (count[i] == 0) continue; res += (count[i] & 1) ? 1 : 2; } return res; } }; ``` -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 86.48.12.134 (日本) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1736767476.A.6E0.html

01/13 20:32, 11月前 , 1F
大師
01/13 20:32, 1F

01/13 23:29, 11月前 , 2F
大師
01/13 23:29, 2F
文章代碼(AID): #1dXFVqRW (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1dXFVqRW (Marginalman)