精華區beta Marginalman 關於我們 聯絡資訊
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
sustainer123: 這題好麻煩 12/17 17:52
oin1104: 今天超麻煩 12/17 18:14