classSolution{public:vector<int>findOrder(intnumCourses,vector<vector<int>>&prerequisites){intn=prerequisites.size();// same as numCoursesvector<int>inDegree(numCourses,0);vector<int>result;unordered_map<int,vector<int>>adj;for(inti=0;i<n;i++){adj[prerequisites[i][0]].push_back(prerequisites[i][1]);}// fill inDegreefor(autoit:adj){for(intnode:adj[it.first])inDegree[node]++;}queue<int>q;for(inti=0;i<numCourses;i++){if(inDegree[i]==0)q.push(i);}while(!q.empty()){intnode=q.front();q.pop();result.push_back(node);for(inte:adj[node]){inDegree[e]--;if(inDegree[e]==0)q.push(e);}}reverse(result.begin(),result.end());if(result.size()==numCourses){returnresult;}return{};}};