安排课程
Posted yunyouhua
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了安排课程相关的知识,希望对你有一定的参考价值。
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()); } } }
写不出来
以上是关于安排课程的主要内容,如果未能解决你的问题,请参考以下文章