Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->...
分类:
其他好文 时间:
2015-08-16 18:01:24
阅读次数:
117
Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->...
分类:
其他好文 时间:
2015-08-16 13:41:29
阅读次数:
422
【129-Sum Root to Leaf Numbers(所有根到叶子结点组组成的数字相加)】【LeetCode-面试算法经典-Java实现】【所有题目目录索引】原题 Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.
An example...
分类:
编程语言 时间:
2015-08-15 06:44:54
阅读次数:
114
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.
Show Tags
Show Similar Proble...
分类:
其他好文 时间:
2015-08-14 01:11:52
阅读次数:
136
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 ...
分类:
其他好文 时间:
2015-08-12 18:38:18
阅读次数:
106
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-08-12 16:53:41
阅读次数:
108
【113-Path Sum II(路径和II)】【LeetCode-面试算法经典-Java实现】【所有题目目录索引】原题 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 b...
分类:
编程语言 时间:
2015-08-12 07:49:38
阅读次数:
150
【112-Path Sum(路径和)】【LeetCode-面试算法经典-Java实现】【所有题目目录索引】原题 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...
分类:
编程语言 时间:
2015-08-11 08:34:13
阅读次数:
147
//给一个连通图,问最少需要添加多少条边才能使得
//任意两个点都有两条不同的路走到
//对于一个强连通分量的所有任意两点都能有两点可以到达
//先用tarjan缩点,缩点以后就是一棵树,对于这个树考虑有几个
//叶子节点 ans = (leaf+1)/2
#include
#include
#include
using namespace st...
分类:
其他好文 时间:
2015-08-10 13:37:50
阅读次数:
94
题目大意:给出一张无向图,问添加多少边才能使得这张无向图变成边双连通分量解题思路:先求出所有的边双连通分量,再将边双连通缩成一个点,通过桥连接起来,这样就形成了一棵无根树了
现在的问题是,将这颗无根树变成边双连通分量网上的解释是:统计出树中度为1的节点的个数,即为叶节点的个数,记为leaf。则至少在树上添加(leaf+1)/2条边,就能使树达到边二连通,所以至少添加的边数就是(leaf+1)/2。...
分类:
其他好文 时间:
2015-08-09 02:01:08
阅读次数:
123