Given a binary tree, return thelevel ordertraversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree{3,9,2...
分类:
编程语言 时间:
2014-07-12 13:13:24
阅读次数:
195
语言:Python描述:使用递归实现 1 class Solution: 2 # @return an integer 3 def numTrees(self, n): 4 if n == 0: 5 return 0 6 eli...
分类:
其他好文 时间:
2014-07-11 23:44:08
阅读次数:
216
题目:Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.说明: 1)二叉树可.....
分类:
其他好文 时间:
2014-07-11 21:07:27
阅读次数:
273
题目:Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.说明: 1)实现与.....
分类:
其他好文 时间:
2014-07-11 20:40:38
阅读次数:
198
/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; ...
分类:
其他好文 时间:
2014-07-11 08:58:23
阅读次数:
207
Description
Let us consider a special type of a binary search tree, called a cartesian tree. Recall that a binary search tree is a rooted ordered binary tree, such that for its every node x the fol...
分类:
其他好文 时间:
2014-07-11 00:12:52
阅读次数:
379
list_to_tree 使用起来十分方便,详细可查看手册。因为我在用的时候需要同时列出所有节点,所以写了一个递归函数,拿出来供大家参考。
/**
* 把返回的数据集转换成Tree
* @access public
* @param array $list 要转换的数据集
* @param string $pid parent标记字段
* @param string $level le...
分类:
Web程序 时间:
2014-07-10 22:30:14
阅读次数:
336
我都不好意思在标题上写这是最短路
这题挺有意思,关键在于把题目所求的量转换为最短路问题。
题意:
给一个无向图,每个结点有权值p[i],每条边有权值w[i]
求使这颗树所有顶点与根节点1联通的最小花费,
最小花费=∑w[i]×∑p[i]
第一个∑是所有边,第二个∑是该边下所有结点的权值和
思路:
通过推导可以发现,对于每个结点,它被算入的花费为 p[i]*d[i],...
分类:
其他好文 时间:
2014-07-10 20:18:43
阅读次数:
177
Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.思路:递归。主要是注意调用时起...
分类:
其他好文 时间:
2014-07-10 14:40:07
阅读次数:
196
题目
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 ...
分类:
其他好文 时间:
2014-07-09 10:32:42
阅读次数:
151