Leetcode-cn.com 2021-12-15
🟡 851.loud-and-rich
🏷️ Tags
#depth_first_search #graph #topological_sort #array
Description
有一组
给你一个数组
现在,返回一个整数数组
Example
🟡 851.loud-and-rich
🏷️ Tags
#depth_first_search #graph #topological_sort #array
Description
有一组
n 个人作为实验对象,从 0 到 n - 1 编号,其中每个人都有不同数目的钱,以及不同程度的安静值(quietness)。为了方便起见,我们将编号为 x 的人简称为 "person x "。给你一个数组
richer ,其中 richer[i] = [ai, bi] 表示 person ai 比 person bi 更有钱。另给你一个整数数组 quiet ,其中 quiet[i] 是 person i 的安静值。richer 中所给出的数据 逻辑自恰(也就是说,在 person x 比 person y 更有钱的同时,不会出现 person y 比 person x 更有钱的情况 )。现在,返回一个整数数组
answer 作为答案,其中 answer[x] = y 的前提是,在所有拥有的钱肯定不少于 person x 的人中,person y 是最安静的人(也就是安静值 quiet[y] 最小的人)。Example
输入:richer = [[1,0],[2,1],[3,1],[3,7],[4,3],[5,3],[6,3]], quiet = [3,2,5,4,6,1,7,0]
输出:[5,5,2,5,4,5,6,7]
解释:
answer[0] = 5,
person 5 比 person 3 有更多的钱,person 3 比 person 1 有更多的钱,person 1 比 person 0 有更多的钱。
唯一较为安静(有较低的安静值 quiet[x])的人是 person 7,
但是目前还不清楚他是否比 person 0 更有钱。
answer[7] = 7,
在所有拥有的钱肯定不少于 person 7 的人中(这可能包括 person 3,4,5,6 以及 7),
最安静(有较低安静值 quiet[x])的人是 person 7。
其他的答案也可以用类似的推理来解释。
Leetcode-cn.com 2022-04-06
🟡 310.minimum-height-trees
🏷️ Tags
#depth_first_search #breadth_first_search #graph #topological_sort
Description
树是一个无向图,其中任何两个顶点只通过一条路径连接。 换句话说,一个任何没有简单环路的连通图都是一棵树。
给你一棵包含
可选择树中任何一个节点作为根。当选择节点
请你找到所有的 最小高度树 并按 任意顺序 返回它们的根节点标签列表。
树的 高度 是指根节点和叶子节点之间最长向下路径上边的数量。
Example
🟡 310.minimum-height-trees
🏷️ Tags
#depth_first_search #breadth_first_search #graph #topological_sort
Description
树是一个无向图,其中任何两个顶点只通过一条路径连接。 换句话说,一个任何没有简单环路的连通图都是一棵树。
给你一棵包含
n 个节点的树,标记为 0 到 n - 1 。给定数字 n 和一个有 n - 1 条无向边的 edges 列表(每一个边都是一对标签),其中 edges[i] = [ai, bi] 表示树中节点 ai 和 bi 之间存在一条无向边。可选择树中任何一个节点作为根。当选择节点
x 作为根节点时,设结果树的高度为 h 。在所有可能的树中,具有最小高度的树(即,min(h))被称为 最小高度树 。请你找到所有的 最小高度树 并按 任意顺序 返回它们的根节点标签列表。
树的 高度 是指根节点和叶子节点之间最长向下路径上边的数量。
Example
输入:n = 4, edges = [[1,0],[1,2],[1,3]]
输出:[1]
解释:如图所示,当根是标签为 1 的节点时,树的高度是 1 ,这是唯一的最小高度树。
Leetcode-cn.com 2022-05-31
🔴 剑指 Offer II 114.Jf1JuT
🏷️ Tags
#depth_first_search #breadth_first_search #graph #topological_sort #array #string
Description
现有一种使用英语字母的外星文语言,这门语言的字母顺序与英语顺序不同。
给定一个字符串列表
请你根据该词典还原出此语言中已知的字母顺序,并 按字母递增顺序 排列。若不存在合法字母顺序,返回
字符串
在第一个不同字母处,如果
如果前面
Example
🔴 剑指 Offer II 114.Jf1JuT
🏷️ Tags
#depth_first_search #breadth_first_search #graph #topological_sort #array #string
Description
现有一种使用英语字母的外星文语言,这门语言的字母顺序与英语顺序不同。
给定一个字符串列表
words ,作为这门语言的词典,words 中的字符串已经 按这门新语言的字母顺序进行了排序 。请你根据该词典还原出此语言中已知的字母顺序,并 按字母递增顺序 排列。若不存在合法字母顺序,返回
"" 。若存在多种可能的合法字母顺序,返回其中 任意一种 顺序即可。字符串
s 字典顺序小于 字符串 t 有两种情况:在第一个不同字母处,如果
s 中的字母在这门外星语言的字母顺序中位于 t 中字母之前,那么 s 的字典顺序小于 t 。如果前面
min(s.length, t.length) 字母都相同,那么 s.length < t.length 时,s 的字典顺序也小于 t 。Example
输入:words = ["wrt","wrf","er","ett","rftt"]
输出:"wertf"
2246.longest-path-with-different-adjacent-characters.pdf
91.2 KB
leetcode.com 2023-01-13
🔴2246.longest-path-with-different-adjacent-characters
🏷️ Tags
#array #string #tree #depth_first_search #graph #topological_sort
🔴2246.longest-path-with-different-adjacent-characters
🏷️ Tags
#array #string #tree #depth_first_search #graph #topological_sort
1632.rank-transform-of-a-matrix.pdf
156.9 KB
leetcode.cn 2023-01-25
🔴1632.rank-transform-of-a-matrix
🏷️ Tags
#greedy #union_find #graph #topological_sort #array #matrix
🔴1632.rank-transform-of-a-matrix
🏷️ Tags
#greedy #union_find #graph #topological_sort #array #matrix
2360.longest-cycle-in-a-graph.pdf
86.5 KB
leetcode.com 2023-03-26
🔴2360.longest-cycle-in-a-graph
🏷️ Tags
#depth_first_search #graph #topological_sort
🔴2360.longest-cycle-in-a-graph
🏷️ Tags
#depth_first_search #graph #topological_sort