Re: [閒聊] 每日LeetCode

看板Marginalman作者 (蘇菲・諾伊恩謬拉)時間6月前 (2023/11/13 11:34), 6月前編輯推噓0(000)
留言0則, 0人參與, 最新討論串511/719 (看更多)
※ 引述《ZooseWu (動物園 公告)》之銘言: : 2785. Sort Vowels in a String : 可以直接用一個陣列依序紀錄字母出現的次數之後填回去 : 少一個排序的動作可以把時間複雜度從 O(nlogn)降到O(n) 對欸 :( 我也是直接用個string去存所有的vowel 然後想說我的怎摸那摸慢 class Solution { public: string sortVowels(string s) { string str; unordered_set<char> vowels = {'A', 'E', 'I', 'O', 'U', 'a', 'e', 'i', 'o', 'u'}; for (auto c: s) { if (vowels.count(c)) str.push_back(c); } sort(str.begin(), str.end()); for (int i = 0, cur = 0; i < s.size() && cur < str.size(); i++) { if (vowels.count(s[i])) { s[i] = str[cur]; cur++; } } return s; } }; -- neuenmuller@atelier:home$ touch plachta touch: cannot touch 'plachta': Permission denied neuenmuller@atelier:home$ sudo touch plachta [sudo] password for neuenmuller: neuenmuller is not in the sudoers file. This incident will be reported. neuenmuller@atelier:home$ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 97.99.29.95 (美國) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1699846490.A.4D4.html ※ 編輯: Neuenmuller (97.99.29.95 美國), 11/13/2023 11:41:45
文章代碼(AID): #1bKPbQJK (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1bKPbQJK (Marginalman)