DAG_DFS_拓扑排序 闷声发大财 21.12.15
文章目录
851.喧闹和富有暴力BFS超时DFS拓扑排序
851.喧闹和富有
暴力BFS超时
class Solution(object):
def loudAndRich(self, richer, quiet):
# DAG
edges = defaultdict(list)
for r in richer:
edges[r[1]].append(r[0])
num = len(quiet)
ans = [0] * num
for i in range(num):
if i not in edges:
ans[i] = i
else:
# BFS
共有 0 条评论