Skip to content

Commit

Permalink
Create 1557. Minimum Number of Vertices to Reach All Nodes.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
sumitsojha88 authored Jul 13, 2021
1 parent ca64ef5 commit ac35f95
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

class Solution {
public:
vector<int> findSmallestSetOfVertices(int n, vector<vector<int>>& edges) {

unordered_map<int,int> mp;
vector<int> ans;
for(int i=0;i<edges.size();i++)
{
mp[edges[i][1]]++;
}
for(int i=0;i<n;i++)
{
if(!mp[i])
{
ans.push_back(i);
}
}

return ans;

}
};

0 comments on commit ac35f95

Please sign in to comment.