Re: [閒聊] 每日leetcode

看板Marginalman作者 (6B)時間1年前 (2024/08/06 09:04), 編輯推噓2(202)
留言4則, 4人參與, 1年前最新討論串645/1548 (看更多)
※ 引述《JerryChungYC (JerryChung)》之銘言: : https://leetcode.com/problems/minimum-number-of-pushes-to-type-word-ii : 3016. Minimum Number of Pushes to Type Word II 睡不著看你版文 medium怎麼比週賽easy還簡單== 看都看了就順手寫掉 不然記在心上更睡不著 好像多開了幾個東西計 大差不差 我要繼續嘗試睡著了 class Solution { public: int minimumPushes(string word) { vector<int> alp(26, 0); for(char c: word){ alp[c - 'a']++; } sort(alp.begin(), alp.end(), [](int a, int b){return a > b;}); int res = 0, add = 1, cnt = 0; for(int i : alp){ res += i * add; cnt++; if(cnt == 8){ cnt = 0; add++; } cout << res << '\n'; } return res; } }; ----- Sent from JPTT on my iPad -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.205.121.194 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1722906271.A.718.html

08/06 09:11, 1年前 , 1F
大師 我也想睡
08/06 09:11, 1F

08/06 09:14, 1年前 , 2F
一起
08/06 09:14, 2F

08/06 09:35, 1年前 , 3F
放過我放過我放過我放過我放過我
08/06 09:35, 3F

08/06 12:30, 1年前 , 4F
大師
08/06 12:30, 4F
文章代碼(AID): #1ciNQVSO (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1ciNQVSO (Marginalman)