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;
        }
    }
}

@@ -78,108 +78,12 @@
 til.
-HashMap;%0Aimport java.util.HashSet;%0Aimport java.util.List;%0Aimport java.util.Set;%0Aimport java.util.Map
+List
 ;%0A%0Ap
@@ -245,161 +245,80 @@
     
-List%3CInteger%3E starts = new ArrayList%3C%3E();%0A            Map%3CInteger, Integer%3E indegree = new HashMap%3C%3E();%0A            for (int i = 0; i %3C edges.size(); i++
+int%5B%5D indegree = new int%5Bn%5D;%0A            for (List%3CInteger%3E edge : edges
 ) %7B%0A
@@ -339,35 +339,29 @@
   in
-t end = edges.get(i)
+degree%5Bedge
 .get(1)
+%5D++
 ;%0A  
@@ -362,32 +362,38 @@
 ++;%0A        
+    %7D%0A
         
 indegree.put
@@ -384,75 +384,50 @@
     
-indegree.put(end, indegree.getOrDefault(end, 0) + 1);%0A            %7D
+    List%3CInteger%3E ans = new ArrayList%3C%3E();
 %0A   
@@ -455,17 +455,31 @@
  0; i %3C 
-n
+indegree.length
 ; i++) %7B
@@ -503,17 +503,16 @@
 if (
-!
 indegree
 .con
@@ -511,23 +511,16 @@
 gree
-.containsKey(i)
+%5Bi%5D == 0
 ) %7B%0A
@@ -539,21 +539,18 @@
         
-start
+an
 s.add(i)
@@ -606,13 +606,10 @@
 urn 
-start
+an
 s;%0A 

refactor 1557