树( Tree):n(n≥O) 个结点的有限集。(只有一个根节点,子集互不相交)节点的度(Degree):节点拥有的子节点数(树的degree = max(各子节点的degree))叶(leaf):degree = 0树的深度(Depth):节点的最大层次树的表示: 双亲表示法:各节点存在一个指针....
分类:
其他好文 时间:
2015-07-05 00:50:11
阅读次数:
241
方法1:递归。int minDepth(TreeNode* root) { if (root == NULL) return 0; if (root->left == NULL) { return minDepth(root->right) + 1; }...
分类:
其他好文 时间:
2015-07-04 23:21:39
阅读次数:
143
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class...
分类:
其他好文 时间:
2015-07-03 22:09:52
阅读次数:
127
题目大意:很简单,只需要找出一颗二叉树的最大深度即可,貌似没有时间和空间的要求。求解方法:更简单,只需要按照宽度优先的方法去查找即可,在这里我用a队列保存待扩展的节点,用b来保存a扩展出来的节点,再利用t中间变量来交换a和b,直到a列队为空时,结束。
注意边界条件,root=NULL时,应该返回0...
分类:
其他好文 时间:
2015-07-03 19:14:06
阅读次数:
110
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class...
分类:
其他好文 时间:
2015-07-03 12:29:21
阅读次数:
132
LeetCode_Maximum Depth of Binary Tree 题解...
分类:
其他好文 时间:
2015-06-30 12:59:49
阅读次数:
94
LeetCode_Minimum Depth of Binary Tree 解题思路...
分类:
其他好文 时间:
2015-06-30 12:59:11
阅读次数:
93
http://oj.leetcode.com/problems/minimum-depth-of-binary-tree/This question is pretty similar to the solution of Maximum Depth of Binary Tree, the only...
分类:
其他好文 时间:
2015-06-30 06:34:15
阅读次数:
138
问题描述:Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never diffe...
分类:
其他好文 时间:
2015-06-29 20:19:54
阅读次数:
104
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 le...
分类:
其他好文 时间:
2015-06-27 06:24:03
阅读次数:
127