BFS is faster to find shortest path from root to leaf node of a tree. But the tradeoff is to use more memory.the basic trategy is to maintain a list t...
分类:
编程语言 时间:
2014-11-11 07:03:12
阅读次数:
259
Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.后序遍历的最后一个元素就是根...
分类:
其他好文 时间:
2014-11-11 00:40:07
阅读次数:
189
题目描述:
Given a binary tree, return the postorder traversal of its nodes' values.
For example:
Given binary tree {1,#,2,3},
1
2
/
3
return [3,2,1].
思路:以中右左的...
分类:
其他好文 时间:
2014-11-10 13:53:20
阅读次数:
163
具体思路参见:二叉树的非递归遍历(转)/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int...
分类:
其他好文 时间:
2014-11-10 11:47:59
阅读次数:
157
这道题A的略烦Binary Tree Level Order Traversal IIGiven a binary tree, return thebottom-up level ordertraversal of its nodes' values. (ie, from left to right...
分类:
其他好文 时间:
2014-11-09 15:09:19
阅读次数:
238
二叉树的各种遍历方法有 前序遍历 中序遍历 后序遍历 层序遍历。其中前三种遍历有递归程序可以实现,但是我们也有必要掌握其非递归版本的算法实现。正好在leetcode中遇到了遍历二叉树的问题,今天在这里一并总结了。首先,引用leetcode中关于二叉树节点的定义。1 // Definition ...
分类:
编程语言 时间:
2014-11-09 12:37:56
阅读次数:
329
Given inorder and postorder traversal of a tree, construct the binary tree.Solution: 1 /** 2 * Definition for binary tree 3 * public class TreeNode .....
分类:
其他好文 时间:
2014-11-09 06:16:44
阅读次数:
215
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 ...
分类:
其他好文 时间:
2014-11-09 06:13:51
阅读次数:
122
题意:
Given a binary tree, return the inorder traversal of its nodes' values.
For example:
Given binary tree {1,#,2,3},
1
2
/
3
return [1,3,2].
Note: Recursive solution is trivial, could you do it iteratively?...
分类:
其他好文 时间:
2014-11-08 19:43:46
阅读次数:
188
Given a binary tree, print it vertically. The following example illustrates vertical order traversal. 1 / \ 2 3 / \ / \ 4 5 6 7 \ \ 8 9The output of p...
分类:
其他好文 时间:
2014-11-08 19:29:26
阅读次数:
212