<awangdev>210. Course Schedule II_1.java
public int[] findOrder(int numCourses, int[][] prerequisites) {
        if (numCourses == 0 || prerequisites == null) {
            return new int[numCourses];
        }

        List[] inDegreeEdges = new ArrayList[numCourses];
        int[] dependencyCount = new int[numCourses];
        
        for (int i = 0; i < numCourses; i++) inDegreeEdges[i] = new ArrayList<>();
        
        for (int[] prerequisite : prerequisites) {
            inDegreeEdges[prerequisite[1]].add(prerequisite[0]);
            dependencyCount[prerequisite[0]]++;
        }
        
        Queue<Integer> queue = new LinkedList<>();
        for (int i = 0; i < numCourses; i++) {
            if (dependencyCount[i] == 0) queue.add(i);
        }

        List<Integer> sortedList = new ArrayList<>();
        while (!queue.isEmpty()) {
            int leafNode = queue.poll();
            sortedList.add(leafNode); 
            List<Integer> dependencies = inDegreeEdges[leafNode];
            for (int node : dependencies) {
                if (--dependencyCount[node] == 0) queue.add(node);
            }
        }
        
        if (sortedList.size() != numCourses) {
            return new int[0];
        }

        int[] rst = new int[sortedList.size()];
        for (int i = 0; i < sortedList.size(); i++) {
            rst[i] = sortedList.get(i);
        }
        return rst;
    }
public int [ ] sample_funcname ( int var_0 , int [ ] [ ] var_1 ) {
  if ( var_0 == 0 || var_1 == null ) {
    return new int [ var_0 ] ;
  }
  List [ ] var_6 = new ArrayList [ var_0 ] ;
  int [ ] var_7 = new int [ var_0 ] ;
  for ( int var_8 = 0 ;
  var_8 < var_0 ;
  var_8 ++ ) var_6 [ var_8 ] = new ArrayList < > ( ) ;
  for ( int [ ] var_9 : var_1 ) {
    var_6 [ var_9 [ 1 ] ] . add ( var_9 [ 0 ] ) ;
    var_7 [ var_9 [ 0 ] ] ++ ;
  }
  Queue < Integer > var_15 = new LinkedList < > ( ) ;
  for ( int var_8 = 0 ;
  var_8 < var_0 ;
  var_8 ++ ) {
    if ( var_7 [ var_8 ] == 0 ) var_15 . add ( var_8 ) ;
  }
  List < Integer > var_16 = new ArrayList < > ( ) ;
  while ( ! var_15 . isEmpty ( ) ) {
    int var_19 = var_15 . poll ( ) ;
    var_16 . add ( var_19 ) ;
    List < Integer > var_20 = var_6 [ var_19 ] ;
    for ( int var_21 : var_20 ) {
      if ( -- var_7 [ var_21 ] == 0 ) var_15 . add ( var_21 ) ;
    }
  }
  if ( var_16 . size ( ) != var_0 ) {
    return new int [ 0 ] ;
  }
  int [ ] var_23 = new int [ var_16 . size ( ) ] ;
  for ( int var_8 = 0 ;
  var_8 < var_16 . size ( ) ;
  var_8 ++ ) {
    var_23 [ var_8 ] = var_16 . get ( var_8 ) ;
  }
  return var_23 ;
}
