Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit bc977af

Browse files
refactor 1557
1 parent ecd89b9 commit bc977af

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/main/java/com/fishercoder/solutions/_1557.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@ public class _1557 {
1111
public static class Solution1 {
1212
public List<Integer> findSmallestSetOfVertices(int n, List<List<Integer>> edges) {
1313
List<Integer> starts = new ArrayList<>();
14-
Map<Integer, Set<Integer>> indegree = new HashMap<>();
14+
Map<Integer, Integer> indegree = new HashMap<>();
1515
for (int i = 0; i < edges.size(); i++) {
1616
int end = edges.get(i).get(1);
17-
if (!indegree.containsKey(end)) {
18-
indegree.put(end, new HashSet<>());
19-
}
20-
indegree.get(end).add(edges.get(i).get(0));
17+
indegree.put(end, indegree.getOrDefault(end, 0) + 1);
2118
}
2219
for (int i = 0; i < n; i++) {
2320
if (!indegree.containsKey(i)) {

0 commit comments

Comments
 (0)