forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_1557.java
27 lines (25 loc) · 834 Bytes
/
_1557.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package com.fishercoder.solutions;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.Map;
public class _1557 {
public static class Solution1 {
public List<Integer> findSmallestSetOfVertices(int n, List<List<Integer>> edges) {
List<Integer> starts = new ArrayList<>();
Map<Integer, Integer> indegree = new HashMap<>();
for (int i = 0; i < edges.size(); i++) {
int end = edges.get(i).get(1);
indegree.put(end, indegree.getOrDefault(end, 0) + 1);
}
for (int i = 0; i < n; i++) {
if (!indegree.containsKey(i)) {
starts.add(i);
}
}
return starts;
}
}
}