[LeetCode] Maximum Depth of Binary Tree
2014-03-16 11:43
447 查看
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.
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 * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: int maxDepth(TreeNode *root) { if(root==NULL) return 0; else { int l=1+maxDepth(root->left); int r=1+maxDepth(root->right); if(l>r) return l; else return r; } } };
相关文章推荐
- Leetcode: Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree - LeetCode
- leetcode:Maximum Depth of Binary Tree
- [LeetCode-104] Maximum Depth of Binary Tree(二叉树最大深度)
- 88_leetcode_Maximum Depth of Binary Tree
- LeetCode - Maximum Depth of Binary Tree(DFS)
- leetcode 104: Maximum Depth of Binary Tree
- LeetCode: Maximum Depth of Binary Tree
- leetcode[104]:Maximum Depth of Binary Tree
- LeetCode 104----Maximum Depth of Binary Tree
- LeetCode-Maximum/Minimum 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]
- LeetCode104: Maximum Depth of Binary Tree
- LeetCode:Maximum Depth of Binary Tree
- LeetCode--No.104--Maximum Depth of Binary Tree
- LeetCode-104 Maximum Depth of Binary Tree
- leetcode 24: Maximum Depth of Binary Tree