public int[] findOrder2(int numCourses, int[][] prerequisites) {
        if (numCourses <= 0 || prerequisites == null) return new int[0];
        HashMap<Integer, List<Integer>> graph = new HashMap<Integer, List<Integer>>();
        for (int i = 0; i < numCourses; ++i) graph.put(i, new ArrayList<Integer>());
        for (int[] p : prerequisites) graph.get(p[1]).add(p[0]);

        int[] visited = new int[numCourses];
        List<Integer> res = new ArrayList<Integer>();
        for (int n : graph.keySet()) {
            if (!canFinish(graph, visited, n, res)) break;
        }

        if (res.size() != numCourses) return new int[0];
        int[] result = new int[numCourses];
        for (int i = 0; i < numCourses; ++i) result[i] = res.get(i);
        return result;
    }