Re: [閒聊] 每日leetcode

看板Marginalman作者 (6B)時間1年前 (2024/12/17 17:46), 編輯推噓1(101)
留言2則, 2人參與, 1年前最新討論串1209/1554 (看更多)
2182. 照字典序重新排 不能重複超過rp次 放好多flag有點醜 時拉比真的好強 嗎的slot幣池 我一整個tts了 class Solution { public: string repeatLimitedString(string s, int rp) { vector<int> ch(26, 0); for(char& c: s){ ch[c-'a']++; } string res; while(true){ bool flag = true, pass = false; for(int i = 25; i >= 0; i--){ if(ch[i] == 0) continue; if(res.size() != 0 and res.back() == ('a' + i)){ pass = true; continue; } flag = false; if(pass){ ch[i]--; res += ('a'+i); break; } else if(ch[i] >= rp){ ch[i] -= rp; res += string(rp, ('a'+i)); break; } else{ res += string(ch[i], ('a'+i)); ch[i] = 0; break; } } if(flag) break; } return res; } }; -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.205.121.194 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1734428762.A.066.html

12/17 17:52, 1年前 , 1F
這題好麻煩
12/17 17:52, 1F

12/17 18:14, 1年前 , 2F
今天超麻煩
12/17 18:14, 2F
文章代碼(AID): #1dOKXQ1c (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1dOKXQ1c (Marginalman)