Re: [閒聊] 每日leetcode

看板Marginalman作者 (6B)時間10月前 (2025/01/24 22:08), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1303/1553 (看更多)
802. 拓撲拉機獸 嗎? class Solution { public: vector<int> eventualSafeNodes(vector<vector<int>>& graph) { int n = graph.size(); vector<vector<int>> adj(n); vector<int> out(n); for(int i = 0; i < n; i++){ for(auto& node: graph[i]){ adj[node].push_back(i); out[i]++; } } vector<int> res; queue<int> ter; for(int i = 0; i < n; i++){ if(out[i] == 0){ ter.push(i); res.push_back(i); } } while(!ter.empty()){ int p = ter.front(); ter.pop(); for(auto& i: adj[p]){ if(--out[i] == 0){ ter.push(i); res.push_back(i); } } } ranges::sort(res); return res; } }; 找cycle感覺也可以 不過寫完ㄌ就這樣ㄅ 怎麼剛回來就沒人刷題ㄌ== 過年放假ㄌ484 -- 很姆的咪 姆之咪 http://i.imgur.com/5sw7QOj.jpg
-- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.205.121.194 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1737727686.A.C08.html
文章代碼(AID): #1davx6m8 (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1davx6m8 (Marginalman)