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.
/**
* Definition for binary tree
...
分类:
其他好文 时间:
2014-08-02 23:32:04
阅读次数:
232
二叉树的深度的概念最值得注意的地方,在于 到"叶子"节点的距离。一般来说,如果直接说“深度”,都是指最大深度,即最远叶子的距离。这里放两道例题,最小深度和最大深度。1. 二叉树的最小深度Given a binary tree, find its minimum depth.The minimum d...
分类:
其他好文 时间:
2014-08-02 23:17:44
阅读次数:
243
题意:二叉树的最小深度注意 1.当root为空的时候直接返回0,因为MIN赋值很大,所以如果不单独预判的话会返回MIN 2.判断树的深度应该到叶子节点,也就是左右子结点都为空的那个结点 3.树的深度的根节点深度为1class Solution {public: void dfs(...
分类:
其他好文 时间:
2014-08-02 20:39:13
阅读次数:
233
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 1
\ ...
分类:
其他好文 时间:
2014-08-02 15:34:34
阅读次数:
221
要搜索的对象是一个rotated sorted array,所以从直觉上时间复杂度应该不会超过O(logn)。起初我想尝试修改binary search来解决这个问题,但仔细思考后发现在不断search的过程中,search的boundary是比较难确定的。解决这个题目的另一个思路就是先把pivot...
分类:
其他好文 时间:
2014-08-02 15:21:23
阅读次数:
359
问题:二叉树中序遍历递归实现/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) :...
分类:
其他好文 时间:
2014-08-02 12:40:33
阅读次数:
162
题目: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-08-02 09:50:13
阅读次数:
232
textField:文本框,文本域。undock:移除。statistics:统计。config:配置。model:模型。auth:认证。decimal:十进制。hexadecimal:十六进制。octal:八进制。binary:二进制。warning=caution:警告。epsilon:极小值。...
分类:
其他好文 时间:
2014-08-02 05:01:35
阅读次数:
248
题目链接:点击打开链接
思路:
我们首先假设这个图都是全0的
用n个点代表行,m个点代表列
用源点向行连一个值x 表示每行1的个数,向列连一个y表示每列y个1
则若行i和列j之间流过一个流量就表示 (i,j) 点填了1
那么若原来图中(i,j)点为0 则花费就是1
若原图中(i,j)点是1,则花费是-1
如此枚举x跑个费用流就好了
==居然把我多年的白书费用流坑掉了。。。
zk...
分类:
其他好文 时间:
2014-08-01 23:15:42
阅读次数:
313
问题:二叉树的最深深度class Solution{public: void dfs(TreeNode *root,int step,int &MAX) { if(root==NULL) { if(MAXleft,step+1); ...
分类:
其他好文 时间:
2014-08-01 22:49:02
阅读次数:
202