Re: [閒聊] 每日leetcode
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
討論串 (同標題文章)
完整討論串 (本文為第 1209 之 1554 篇):