和上一题类似,这里是要记录每条路径并返回结果。Given the below binary tree andsum = 22, 5 / \ 4 8 / / \ 11 13 4 ...
分类:
其他好文 时间:
2014-11-30 13:44:42
阅读次数:
188
判断一棵树是不是平衡二叉树。思路:递归。每个节点的左右子树是平衡二叉树,并且左右子树的高度相差不超过一。/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * Tr...
分类:
其他好文 时间:
2014-11-30 00:24:11
阅读次数:
288
题目:返回根节点到最近的叶子节点的距离。例如:{1,2},其中2是1的左子树,1的右子树为空,2为叶子节点,那么此时返回2.如果用简单的递归,以为是返回左右两边的最小值加1,那么上面那个case就错了,因为如果返回左右两边最小值加1的话,上面1的右边是0,所以返回1,但我们想要的是2.所以要另外注意...
分类:
其他好文 时间:
2014-11-30 00:22:57
阅读次数:
118
把一个有序链表构成成平衡二叉树。和上一题有一点像。思路一:将有序链表存在一个数组里。然后根据每次访问中间节点当做根节点递归左右子树节点即可。代码如下:/** * Definition for singly-linked list. * struct ListNode { * int val;...
分类:
其他好文 时间:
2014-11-29 22:53:04
阅读次数:
271
利用更有序数组,构造平衡二叉树。思路,递归,每次中间节点为根节点,然后递归获得左右子树。/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *...
分类:
其他好文 时间:
2014-11-29 22:52:43
阅读次数:
239
Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 ...
分类:
其他好文 时间:
2014-11-29 21:37:03
阅读次数:
330
Convert Sorted Array to Binary Search TreeGiven an array where elements are sorted in ascending order, convert it to a height balanced BST.这题思路参照Conve...
分类:
其他好文 时间:
2014-11-29 20:07:35
阅读次数:
178
要求:Given a binary tree, flatten it to a linked list in-place.将二叉树转化为平坦序列的树。比如:结题思路:该题有个提示,转化后的树的序列正好是二叉树前序遍历所得到的序列,所以,该题第一个思路就是利用前序遍历的方式来做。第二个思路:我们可以利...
分类:
其他好文 时间:
2014-11-29 18:48:51
阅读次数:
196
要求:此题正好和Maximum Depth of Binary Tree一题是相反的,即寻找二叉树的最小的深度值:从根节点到最近的叶子节点的距离。结题思路:和找最大距离不同之处在于:找最小距离要注意(lleft);13 int r = minDepth(root->right);14 ...
分类:
其他好文 时间:
2014-11-29 18:47:40
阅读次数:
182
AdaBoost Binary ClassifyAdaBoost MultidimensionalWEKA源码分析
分类:
编程语言 时间:
2014-11-29 18:46:37
阅读次数:
133