【题目】
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.
For example:
Given the following binary tre...
分类:
其他好文 时间:
2015-04-06 11:32:47
阅读次数:
173
1.题目描述:点击打开链接
2.解题思路:本题是训练二叉树的一道好题。首先要解决读数据问题,根据题意,当输入为“()”时,结束该组数据读入,当没有字符串时,整个输入结束。因此可以专门编写一个readin()函数,类型设置为bool型,遇到第一种情况时返回true,遇到第二种情况返回false,主程序中只要发现readin返回false时就break,结束整个大循环。
接下来要建立二叉树,首先为...
分类:
其他好文 时间:
2015-03-30 09:27:30
阅读次数:
124
struct TreeNode{
ElemtType val;
TreeNode *left,*right;
};
1.判定一棵二叉树是否是完全二叉树
借助于层次遍历的算法,将所有结点入队列,包括空结点。出队遇到空结点时,查看其后是否有非空结点,若有,则不是完全二叉树。bool isComplete(TreeNode* root){
TreeNode* Q[Max...
分类:
其他好文 时间:
2015-03-28 23:18:46
阅读次数:
373
图的广度优先/层次 遍历(BFS) c++ 队列实现
分类:
编程语言 时间:
2015-02-21 08:36:33
阅读次数:
290
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,#,#,15,7},
3...
分类:
其他好文 时间:
2015-02-13 20:01:56
阅读次数:
136
原题地址二叉树的层次遍历代码: 1 vector > levelOrder(TreeNode *root) { 2 vector > res; 3 queue layer; 4 5 layer.push(root); 6 ...
分类:
其他好文 时间:
2015-02-02 12:17:03
阅读次数:
171
原题地址二叉树层次遍历,最后把遍历结果翻转一下即可代码: 1 vector > levelOrderBottom(TreeNode *root) { 2 vector > res; 3 queue layer; 4 5 layer.p...
分类:
其他好文 时间:
2015-02-02 12:15:00
阅读次数:
209
Given a binary tree, findits maximum depth.
The maximum depth is thenumber of nodes along the longest path from the root node down to the farthestleaf node.
可用递归,效率低。
这里用类似层次遍历的算法。设置一个队列和两个int变量...
分类:
其他好文 时间:
2015-01-30 09:10:56
阅读次数:
261
原题地址基本数据结构操作,二叉树的层次遍历。代码: 1 vector > zigzagLevelOrder(TreeNode *root) { 2 vector > res; 3 vector layer; 4 bool l2r = true; 5 ...
分类:
其他好文 时间:
2015-01-29 20:49:11
阅读次数:
169
高德iOS面试整理(顺序有些乱,一面跪了)
1.简单自我介绍
2.聊c语言
3.两个数比较大小不用if和三目运算符
4.int转化为bit数组
5.多态和隐藏
6.const 和define区别
7.String类实现拷贝构造函数注意事项,是否有必要重写
数据结构
1.树层次遍历
2.链表删除
iOS
1.通知和delegate
2.ViewContr...
分类:
移动开发 时间:
2015-01-26 22:55:05
阅读次数:
242