-
-
Save sarthakpranesh/7ce0beaea96239ad86a94c8c2e7f6018 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public List<Integer> findSmallestSetOfVertices(int n, List<List<Integer>> edges) { | |
List<Integer> l = new ArrayList<>(); | |
List<Integer> no = new ArrayList<>(); | |
for (int i = 0; i < edges.size(); ++i) { | |
no.add(edges.get(i).get(1)); | |
int isThereInL = l.indexOf(edges.get(i).get(1)); | |
if (isThereInL != -1) { | |
l.remove(isThereInL); | |
} | |
int curEdge = edges.get(i).get(0); | |
if (l.indexOf(curEdge) != -1 || no.indexOf(curEdge) != -1) { | |
continue; | |
} | |
l.add(curEdge); | |
} | |
return l; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment