pinprerequisites:graph[p].append(c)indegree[c]+=1# 筛选出不需要预先课程的课queue=[iforiinrange(n)ifindegree[i]==0]path=[]# 上课顺序whilequeue:# queue 里的课程都是已满足或无预先课程的,挑出第一门i来读i=queue.pop(0)path.append(i)# 当我们完成课程i后
【207】Course Schedule 【210】Course Schedule II 【269】Alien Dictionary 【329】Longest Increasing Path in a Matrix 【444】Sequence Reconstruction
You may assume that there are no duplicate edges in the input prerequisites. click to show more hints. publicclassSolution {publicbooleancanFinish(intnumCourses,int[][] prerequisites) {int[] pre =newint[numCourses]; List<Integer>[] satisfies =newList[numCourses];for(inti=0; i<numCourses; ...
拓扑排序TopologicalSort 2018-05-02 16:26:07 一、拓扑排序 有向无环图(Directed acyclic graph,DAG)必定存在拓扑排序;非DAG没有拓扑排序一说。 二、拓扑排序算法 通常拓扑排序算法可以在O(n)的时间复杂度完成,具体来说是O(V + E)。 下面以leetcode207为例来介绍 ...
Leetcode Sorting ❓s: 912. Sort an Array 922. Sort Array By Parity II 973. K Closest Points to Origin 977. Squares of a Sorted Array 1470. Shuffle the Array 1480. Running Sum of 1d Array 1512. Number of Good Pairs 1672. Richest Customer Wealth 1678. Goal Parser Interpretation 1720...
中等 210. 课程表 II 59.0% 中等 269. 火星词典 37.8% 困难 310. 最小高度树 43.8% 中等 329. 矩阵中的最长递增路径 53.0% 困难 444. 序列重建 32.2% 中等 631. 设计 Excel 求和公式 33.9% 困难 802. 找到最终的安全状态 59.7% 中等 851. 喧闹和富有 64.2% 中等 913. 猫和老鼠 49.5% 困难 1059....