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
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
我们知道,要把一个非边双连通图构造成一个边双连通图,只需把这个图化简(边双连通分量缩点)成一个树,然后 找出叶子节点个数leaf,(leaf+1)/2就是要新添加的边数。 现在,对与有向图来说,我们需要求加最少的边,使得一个非强连通图变成一个强连通图,最少的边数是多少? 同样的,我们需要...
分类:
其他好文 时间:
2015-03-28 17:00:41
阅读次数:
192
【this】在没有new一个对象前,this不知道指的是什么;当new出一个对象时,this指的是当前对象的引用。【分析】int i =0;这里的i指的是成员变量;Leaf(int i)这里的i是形参i(二者都在栈中,但不是一个变量)。this.i = i;后面的i未作说明,这是根据就近原则确定i指...
分类:
编程语言 时间:
2015-03-20 23:39:09
阅读次数:
191
https://leetcode.com/problems/sum-root-to-leaf-numbers/Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a num...
分类:
其他好文 时间:
2015-03-19 17:51:26
阅读次数:
150
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.思路分析:这题比较简单,关于树的题目通常都可以用递归解决,这题也不例外,递归解法的思...
分类:
其他好文 时间:
2015-03-19 06:23:34
阅读次数:
126
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.Fo...
分类:
其他好文 时间:
2015-03-18 15:20:00
阅读次数:
131
第一次写的解法,。对于只有一个儿子的节点重复了两次 。。结果就弄复杂了。。我也觉得不应该能有这么多的重复嘛
/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) ...
分类:
其他好文 时间:
2015-03-17 22:00:13
阅读次数:
130
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(...
分类:
其他好文 时间:
2015-03-17 21:28:07
阅读次数:
118