Re: [閒聊] 每日LeetCode已回收

看板Marginalman作者 (廷廷)時間1年前 (2024/01/30 20:42), 編輯推噓1(100)
留言1則, 1人參與, 1年前最新討論串634/719 (看更多)
為了下次codility不要烙賽 再寫一題 map真好用 49. Group Anagrams class Solution { public: vector<vector<string>> groupAnagrams(vector<string>& strs) { vector<vector<string>> ans; unordered_map<string, int> mp; for(const string& str:strs){ string sstr = str; sort(sstr.begin(), sstr.end()); if(mp.count(sstr)){ ans[mp[sstr]].push_back(str); } else{ mp[sstr]=ans.size(); ans.push_back({str}); } } return ans; } }; -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.250.73.119 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1706618524.A.9E4.html

01/30 20:43, 1年前 , 1F
大師
01/30 20:43, 1F
文章代碼(AID): #1bkEwSda (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1bkEwSda (Marginalman)