首页 > 代码库 > 安排课程
安排课程
public class Solution { /** * @param numCourses a total of n courses * @param prerequisites a list of prerequisite pairs * @return the course order */ private class Node { int label; ArrayList<Integer> pre; /* public node(int la; ArrayList<Integer> prerequist) { label = la; pre = pre; } */ } public int[] findOrder(int numCourses, int[][] prerequisites) { // Write your code here if (prerequisites == null || prerequisites.length == 0 || prerequisites[0].length == 0) { return new int[0]; } int[] result = new int[numCourses]; ArrayList<int> order = new ArrayList<int>(); Map<int node, ArrayList<int> request> indegree = getIndegree(numCourses,prerequisites); Queue<int> queue = new LinkedList<>(); for (int i = 0; i < numCourses; i++) { if (indegree.get(i) == 0) { queue.offer(i); order.add(i); } } while (!queue.isEmpty()) { int node = queue.poll; for (int i = 0; i < prerequisites.length; i++) { if(prerequisites[i][1] = node) { prerequisites[i][0] } } } } private Map<int node, ArrayList<int> request> getIndegree (int numCourses, int[][] prerequisites) { Map<int node, ArrayList<int> request> indegree = new HashMap(); //init map for (int j = 0; j < numCourses; j++) { indegree.put(j, new ArrayLisr<int>()); } for (int i = 0; i < prerequisites.length; i++) { indegree.put(prerequisites[i][0], indegree.get(prerequisites[i][0]).add()); } } }
写不出来
安排课程
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。