maximum-depth-of-binary-tree
2017-09-26 16:19
225 查看
题目:
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.
程序:
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.
程序:
class Solution { public: int maxDepth(TreeNode *root) { if(root==NULL) return 0; int h1=0,h2=0; if(root->left) h1=maxDepth(root->left); if(root->right) h2=maxDepth(root->right); return h1>h2?h1+1:h2+1; } };
相关文章推荐
- LeetCode-Maximum/Minimum Depth of Binary Tree
- Maximum Depth of Binary Tree
- LeetCode——Maximum Depth of Binary Tree
- 迭代----- Maximum Depth of Binary Tree
- [LeetCode]Maximum Depth of Binary Tree
- [leetcode]_Maximum Depth of Binary Tree
- [LeetCode] Maximum Depth of Binary Tree
- LeetCode:Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree 二叉树的最大深度
- 104 Maximum Depth of Binary Tree
- 4.1 leetcode -1 maximum-depth-of-binary-tree
- leetcode — maximum-depth-of-binary-tree
- Maximum Depth of Binary Tree
- LeetCode——Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- 【Leetcode】Maximum Depth of Binary Tree
- LeetCode | Maximum Depth of Binary Tree
- Leetcode Maximum Depth of Binary Tree