原题地址二叉树的层次遍历代码: 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
题目链接:https://oj.leetcode.com/problems/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, l...
分类:
其他好文 时间:
2015-02-01 09:37:45
阅读次数:
155
Q:Given a binary tree, return the postorder traversal
of its nodes' values.
Note:Recursive
solution is trivial, could you do it iteratively?
题目的意思就是不用递归求二叉树的后序遍历。
后续遍历的递归方式很简单,首先遍历左子树,然后遍历右子树,最...
分类:
其他好文 时间:
2015-01-31 14:49:58
阅读次数:
156
Given a binary tree, return the inorder traversal of itsnodes' values.
For example:
Given binary tree {1,#,2,3},
1
2
/
3
return [1,3,2].
Note: Recursive solution istri...
分类:
其他好文 时间:
2015-01-30 22:53:42
阅读次数:
203
Given a binary tree, return the preorder traversal of itsnodes' values.
For example:
Given binary tree {1,#,2,3},
1
2
/
3
return [1,2,3].
Note: Recursive solution istr...
分类:
其他好文 时间:
2015-01-30 22:53:36
阅读次数:
234
Given inorder and postorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.
#include
#include
typedef struct TreeNode {
int v...
分类:
其他好文 时间:
2015-01-30 22:50:28
阅读次数:
266
深度优先搜索(DFS:Depth-First Search)是一种图搜索策略,其将搜索限制到 2 种操作:(a) 访问图中的一个节点;(b) 访问该节点的子节点。对图的深度优先搜索与对树(Tree)的深度优先遍历(Depth First Traversal)是类似的,区别在于图中可能存在环,所以可能...
分类:
其他好文 时间:
2015-01-30 22:28:49
阅读次数:
311
【方法】
将数组的首地址和数组的长度传入函数中
【例如】
函数声明
void traversal(int *array ,int n);
函数调用
traversal (array,n);
【遍历实例】
【求最值实例】...
分类:
编程语言 时间:
2015-01-30 16:09:40
阅读次数:
196
原题地址二叉树基本操作[ ]O[ ][ ][ ]O代码: 1 TreeNode *restore(vector &inorder, vector &postorder, int ip, int pp, int len) { 2 if (len == 0) 3 ...
分类:
其他好文 时间:
2015-01-30 10:36:55
阅读次数:
186