Given inorder and postorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.
思路:这题和上题类似,前序第一个是根节点,后序遍历最后一个是根节点。其余步骤类似。
代码如下:
/**
*...
分类:
其他好文 时间:
2015-08-01 22:10:16
阅读次数:
150
Given preorder and inorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.
思路:首先根据前序遍历得到根节点,然后在中序遍历中得到根节点的位置,左边的为左子树,右边的为右子树。
然后再...
分类:
其他好文 时间:
2015-08-01 22:09:32
阅读次数:
138
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 example:
Given binary tree {3,9,20,#,#,15,7},
...
分类:
其他好文 时间:
2015-08-01 22:07:00
阅读次数:
129
Question
Implement int sqrt(int x).
Compute and return the square root of x.
My Solution
class Solution {
public:
int mySqrt(int x) {
/**
* binary search a from [0, x], where a^2 = x....
分类:
其他好文 时间:
2015-08-01 22:06:03
阅读次数:
87
error: Embedded binary's bundle identifier is not prefixed with the parent app's bundle identifier.
错误原因: iPhone APP, watch APP 和 watch extension 三者的bundle ID 不符合苹果的命名规范.其命名规范必须遵循固定的格式....
分类:
移动开发 时间:
2015-08-01 17:25:40
阅读次数:
743
understanding of (lower bound,upper bound) binary search...
分类:
编程语言 时间:
2015-08-01 15:46:53
阅读次数:
167
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.
According to the
definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes ...
分类:
其他好文 时间:
2015-08-01 15:45:56
阅读次数:
94
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.
According to the
definition of LCA on Wikipedia: “The lowest common ancestor is defined betwee...
分类:
其他好文 时间:
2015-08-01 13:02:22
阅读次数:
98
Two elements of a binary search tree (BST) are swapped by mistake.
Recover the tree without changing its structure.
Note:
A solution using O(n) space is pretty straight forward. Could you devise a ...
分类:
其他好文 时间:
2015-08-01 11:34:59
阅读次数:
108
Binary Tree Traversals
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4438 Accepted Submission(s): 2025
Problem Description
A binary tree...
分类:
其他好文 时间:
2015-08-01 10:03:55
阅读次数:
124