精華區beta Marginalman 關於我們 聯絡資訊
791. Custom Sort String 你板大師都好猛 剩我只會水桶了 string customSortString(string order, string s) { vector<int> cnt(26,0); for(auto c : s) { cnt[c-'a']++; } string ans = ""; for(auto c : order) { ans += string(cnt[c-'a'], c); cnt[c-'a'] = 0; } for(int i=0; i<26; i++) { if(cnt[i] > 0) { ans += string(cnt[i], 'a'+i); } } return ans; } -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.171.13.229 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1710168829.A.B12.html ※ 編輯: DJYOSHITAKA (1.171.13.229 臺灣), 03/11/2024 22:54:11
Rushia: 排比較快 03/11 22:55
yam276: 我懶 可以塞HashMap就塞 03/11 22:55
JIWP: 剩我什麼都不會了 03/11 22:59
sustainer123: 剩我什麼都不會了 03/11 23:02
DJYOSHITAKA: 是在len<200這個scale排比較快嗎 03/11 23:02
DJYOSHITAKA: 水桶確實比較多小步驟 03/11 23:03
Rushia: 計數排序時間複雜度是O(n) 屌打高等排序的O(nlogn) 03/11 23:05