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
There are a total ofncourses you have to take, labeled from0ton - 1. Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pair:[0,1] Given the total number of courses and a list of prerequisite pairs, is it po...
🎭 PsuendoCode Union Find Algorithm Pattern ♾ ⏰: O(V * logV) 🪐: O function find(int[] parent, i) { if (parent[i] == -1) return i; return find(parent, parent[i]); function union(int[] parent, x, y) { xset = find(parent, x); yset = find(parent, y); parent...
中等 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....