描述广度优先搜索算法(Breadth First Search)与树的层序遍历(level-order traversal)类似,基本思想是思想是:
从图中某顶点v出发,访问v之后,并将其访问标志置为已被访问,即visited[i]=1;
依次访问v的各个未曾访问过的邻接点;
分别从这些邻接点出发依次访问它们的邻接点,并使得“先被访问的顶点的邻接点先于后被访问的顶点的邻接点被访问,直至图中所有已被访...
分类:
其他好文 时间:
2015-04-17 22:22:50
阅读次数:
157
Binary Tree Zigzag Level Order TraversalTotal Accepted:31183Total Submissions:117840My SubmissionsQuestionSolutionGiven a binary tree, return thezigza...
分类:
其他好文 时间:
2015-04-17 21:53:46
阅读次数:
123
#include#include#includeusing namespace std;// Definition for binary tree struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int...
分类:
其他好文 时间:
2015-04-17 21:51:07
阅读次数:
141
题目链接:Binary Tree Level Order Traversal
II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).
For exam...
分类:
其他好文 时间:
2015-04-17 18:16:21
阅读次数:
176
Binary Tree Level Order Traversal IITotal Accepted:37829Total Submissions:122499My SubmissionsQuestionSolutionGiven a binary tree, return thebottom-up...
分类:
其他好文 时间:
2015-04-16 12:23:02
阅读次数:
176
Given a binary tree, return thelevel ordertraversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree{3,9,2...
分类:
其他好文 时间:
2015-04-16 12:08:03
阅读次数:
148
题目链接:Binary Tree Zigzag Level
Order Traversal
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and a...
分类:
其他好文 时间:
2015-04-16 10:24:56
阅读次数:
116
题目链接:Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).
For example:
Given binary tree {3,9,20,#...
分类:
其他好文 时间:
2015-04-16 09:03:12
阅读次数:
160
抓住那头牛(POJ3278)农夫知道一头牛的位置,想要抓住它。农夫和牛都位于数轴上,农夫起始位于点N(0#include#include#includeusing namespace std;#define MAX_SIZE 10000//查询最大的范围int visited[MAX_SIZE];/...
分类:
其他好文 时间:
2015-04-14 19:22:13
阅读次数:
115
求一棵树的最大深度 思路:广度优先搜索即可 class Solution {public: int maxDepth(TreeNode *root) { int depth = 0; if (!root) return depth; queue nodeQue; nodeQue.push(root)...
分类:
其他好文 时间:
2015-04-11 11:38:05
阅读次数:
117