
DFS
文章平均质量分 61
myangel_xy
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
【LeetCode】207. Course Schedule判断有向图是否有环
1、问题描述输入:n, [[1,0], [2,1], …., [n, n-1], [0,1], …..],假设没有重复的边 n表示总共0~n-1门课程,即n个节点 [1,0]表示先上课程0,才能上课程1,即0→1有一条有向边 输出:能否完成所有课程,即无环true/有环false2、思路DFS。 除了树边,假设存在一条边v→u,则有如下性质: 1. pre(u) < pre(v),pos原创 2017-05-29 10:03:56 · 1278 阅读 · 0 评论 -
【LeetCode】210. Course Schedule II
问题描述在207.Course Schedule问题的基础上,求出能够完成所有课程的其中一种可能的顺序方案,如果不存在,则返回空数组。问题就变成:如何按照post值递减来保存节点。class Solution { public: //1、设置计步器,全局变量 int count = 0; vector<int> findOrder(int numCourses, vector<原创 2017-06-01 18:37:39 · 224 阅读 · 0 评论 -
【LeetCode】No.257 Binary Tree Paths
【原题】 Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1 / \ 2 3 \ 5 All root-to-leaf paths are: ["1->2->5", "1->3"] 【翻译】 要求输出一个原创 2017-03-18 18:26:40 · 194 阅读 · 0 评论