Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.
For example:
Given the below binary tree and sum ...
分类:
其他好文 时间:
2015-03-30 13:20:37
阅读次数:
84
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.
For example:
Given the below binary tree and sum = 22,
5
/ \...
分类:
其他好文 时间:
2015-03-30 13:14:32
阅读次数:
89
题目:
Given preorder and inorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.
思路:根据前序和中序的特点 递归调用创建二叉树
#include
#include
u...
分类:
其他好文 时间:
2015-03-30 11:26:36
阅读次数:
122
Two elements of a binary search tree (BST) are swapped by mistake.
Recover the tree without changing its structure.
#include
#include
#include
using namespace std;
struct TreeNode {
int val;...
分类:
其他好文 时间:
2015-03-30 11:24:41
阅读次数:
121
和上面的题目相似 思路也是类似
Tree* helpersecond(vector& inorder,int in_begin,int in_end,vector& post,int post_begin,int post_end)
{
Tree* root =NULL;
int mid;
int i;
if(in_begin > in_end)
{
return NULL;
}...
分类:
其他好文 时间:
2015-03-30 11:24:10
阅读次数:
117
Given a binary tree
struct TreeLinkNode {
TreeLinkNode *left;
TreeLinkNode *right;
TreeLinkNode *next;
}
Populate each next pointer to point to its next right node....
分类:
其他好文 时间:
2015-03-30 11:18:59
阅读次数:
108
Path Sum IIGiven a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tr...
分类:
其他好文 时间:
2015-03-30 10:52:04
阅读次数:
158
Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened t...
分类:
其他好文 时间:
2015-03-30 10:52:04
阅读次数:
106
Given a binary tree
struct TreeLinkNode {
TreeLinkNode *left;
TreeLinkNode *right;
TreeLinkNode *next;
}
Populate each next pointer to point to its next right node. ...
分类:
其他好文 时间:
2015-03-30 09:38:00
阅读次数:
163
题目:
Given n, how many structurally unique BST's (binary search trees) that store values 1...n?
For example,
Given n = 3, there are a total of 5 unique BST's.
1 3 3 2 ...
分类:
其他好文 时间:
2015-03-29 15:11:19
阅读次数:
106