原文链接: https://leetcode-cn.com/problems/course-schedule 英文原文There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take…
标签详情
拓扑排序 分类
原文链接: https://leetcode-cn.com/problems/course-schedule-ii 英文原文There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must t…
原文链接: https://leetcode-cn.com/problems/minimum-height-trees 英文原文A tree is an undirected graph in which any two vertices are connected by exactly one path. In other words, any connected graph without simple cycles is a tree. Given a tree of n nodes la…
原文链接: https://leetcode-cn.com/problems/longest-increasing-path-in-a-matrix 英文原文Given an m x n integers matrix, return the length of the longest increasing path in matrix. From each cell, you can either move in four directions: left, right, up, or dow…
原文链接: https://leetcode-cn.com/problems/find-eventual-safe-states 英文原文There is a directed graph of n nodes with each node labeled from 0 to n - 1. The graph is represented by a 0-indexed 2D integer array graph where graph[i] is an integer array of nod…
原文链接: https://leetcode-cn.com/problems/loud-and-rich 英文原文There is a group of n people labeled from 0 to n - 1 where each person has a different amount of money and a different level of quietness. You are given an array richer where richer[i] = [ai, b…
原文链接: https://leetcode-cn.com/problems/rank-transform-of-a-matrix 英文原文Given an m x n matrix, return a new matrix answer where answer[row][col] is the rank of matrix[row][col]. The rank is an integer that represents how large an element is compared to…
原文链接: https://leetcode-cn.com/problems/sort-items-by-groups-respecting-dependencies 英文原文There are n items each belonging to zero or one of m groups where group[i] is the group that the i-th item belongs to and it's equal to -1 if the i-th item belong…
原文链接: https://leetcode-cn.com/problems/count-ways-to-build-rooms-in-an-ant-colony 英文原文You are an ant tasked with adding n new rooms numbered 0 to n-1 to your colony. You are given the expansion plan as a 0-indexed integer array of length n, prevRoom,…
原文链接: https://leetcode-cn.com/problems/course-schedule-iv 英文原文There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must t…
原文链接: https://leetcode-cn.com/problems/strange-printer-ii 英文原文There is a strange printer with the following two special requirements: On each turn, the printer will print a solid rectangular pattern of a single color on the grid. This will cover up t…
原文链接: https://leetcode-cn.com/problems/largest-color-value-in-a-directed-graph 英文原文There is a directed graph of n colored nodes and m edges. The nodes are numbered from 0 to n - 1. You are given a string colors where colors[i] is a lowercase English …
原文链接: https://leetcode-cn.com/problems/number-of-ways-to-arrive-at-destination 英文原文You are in a city that consists of n intersections numbered from 0 to n - 1 with bi-directional roads between some intersections. The inputs are generated such that yo…
原文链接: https://leetcode-cn.com/problems/parallel-courses-iii 英文原文You are given an integer n, which indicates that there are n courses labeled from 1 to n. You are also given a 2D integer array relations where relations[j] = [prevCoursej, nextCoursej] …
原文链接: https://leetcode-cn.com/problems/Za25hA 英文原文 中文题目秋游中的小力和小扣设计了一个追逐游戏。他们选了秋日市集景区中的 N 个景点,景点编号为 1~N。此外,他们还选择了 N 条小路,满足任意两个景点之间都可以通过小路互相到达,且不存在两条连接景点相同的小路。整个游戏场景可视作一个无向连通图,记作二维数组 `edges`,数组中以 `[a,b]` 形式表示景点 a 与景点 b 之间有一条小路连通。 小力和小扣只能沿景点间的小路移动。小力的目标…
原文链接: https://leetcode-cn.com/problems/fpTFWP 中文题目给定一个 m x n 整数矩阵 matrix ,找出其中 最长递增路径 的长度。 对于每个单元格,你可以往上,下,左,右四个方向移动。 不能 在 对角线 方向上移动或移动到 边界外(即不允许环绕)。 示例 1: 输入:matrix = [[9,9,4],[6,6,8],[2,1,1]] 输出:4 解释:最长递增路径为 [1, 2, 6, 9]。 示例 2: 输入:matrix = [[3,4,5]…
原文链接: https://leetcode-cn.com/problems/QA2IGt 中文题目现在总共有 numCourses 门课需要选,记为 0 到 numCourses-1。 给定一个数组 prerequisites ,它的每一个元素 prerequisites[i] 表示两门课程之间的先修顺序。 例如 prerequisites[i] = [ai, bi] 表示想要学习课程 ai ,需要先完成课程 bi 。 请根据给出的总课程数 numCourses 和表示先修顺序的 prereq…
原文链接: https://leetcode-cn.com/problems/Jf1JuT 中文题目现有一种使用英语字母的外星文语言,这门语言的字母顺序与英语顺序不同。 给定一个字符串列表 words ,作为这门语言的词典,words 中的字符串已经 按这门新语言的字母顺序进行了排序 。 请你根据该词典还原出此语言中已知的字母顺序,并 按字母递增顺序 排列。若不存在合法字母顺序,返回 "" 。若存在多种可能的合法字母顺序,返回其中 任意一种 顺序即可。 字符串 s 字典顺序小于 字符串 t 有两…
原文链接: https://leetcode-cn.com/problems/ur2n8P 中文题目请判断原始的序列 org 是否可以从序列集 seqs 中唯一地 重建 。 序列 org 是 1 到 n 整数的排列,其中 1 ≤ n ≤ 104。重建 是指在序列集 seqs 中构建最短的公共超序列,即 seqs 中的任意序列都是该最短序列的子序列。 示例 1: 输入: org = [1,2,3], seqs = [[1,2],[1,3]] 输出: false 解释:[1,2,3] 不…