-
Notifications
You must be signed in to change notification settings - Fork 305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Day 11 | 7/27 #21
Comments
Lintcode127. Topological Sorting
def topSortBFS(self, graph):
indegree = {}
ans = []
for g in graph:
for n in g.neighbors:
if n not in indegree:
indegree[n] = 1
else:
indegree[n] += 1
q = []
for g in graph:
if g not in indegree:
q.append(g)
while q:
temp = q.pop(0)
ans.append(temp)
for n in temp.neighbors:
indegree[n] -= 1
if indegree[n] == 0:
q.append(n)
return ans |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
今日计划 | BFS
搜集BFS资源,以及针对经典题开刷。
Comeback Later:
The text was updated successfully, but these errors were encountered: