public int[] findOrder(int numCourses, int[][] prerequisites) {
		int[] result = new int[numCourses];
		if (prerequisites == null || prerequisites.length == 0) {
			for (int i = 0; i < numCourses; i++) {
				result[i] = i;
			}
			return result;
		} else {
			HashSet<Integer>[] graph = new HashSet[numCourses];
			for (int i = 0; i < numCourses; i++) {
				graph[i] = new HashSet<Integer>();
			}
			for (int[] pair : prerequisites) {
				graph[pair[1]].add(pair[0]);
			}
			boolean[] visited = new boolean[numCourses];
			boolean[] visiting = new boolean[numCourses];
			ArrayList<Integer> list = new ArrayList<Integer>();

			for (int i = 0; i < numCourses; i++) {
				if (!visited[i]) {
					boolean dfsResult = dfs(graph, i, visited, visiting, list);
					if (!dfsResult)
						return result;
				}
			}

			for (int i = 0; i < numCourses; i++) {
				result[i] = list.get(numCourses - 1 - i);
			}
			return result;
		}

	}