[LeetCode]Maximum Depth of Binary Tree
来源:互联网 发布:淘宝仓管岗位职责 编辑:程序博客网 时间:2024/06/09 21:36
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.
注意对于root为NULL时返回0。代码如下:
/** * 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;} int leftdepth = maxDepth(root->left); int rightdepth = maxDepth(root->right); int maxdepth = max(leftdepth,rightdepth)+1; return maxdepth; }};
0 0
- Leetcode - Tree - Maximum Depth of Binary Tree
- [leetcode][tree] Maximum Depth of Binary Tree
- LeetCode Maximum Depth of Binary Tree
- [Leetcode] Maximum Depth of Binary Tree
- leetcode 24: Maximum Depth of Binary Tree
- [LeetCode] Maximum Depth of Binary Tree
- Leetcode 104 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
- Leetcode: 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
- LeetCode | Maximum Depth of Binary Tree
- 【leetcode】Maximum Depth of Binary Tree
- Erlang与Flash的Socket通讯-01
- Android虚拟机横竖屏间的切换
- Erlang开发MMO的一些思考
- 【Android开发日记】微信API 分享到朋友圈
- Struts2+MyBatis3.1.0+Spring3.1.0整合之道二SqlSessionTemplate
- [LeetCode]Maximum Depth of Binary Tree
- 关于java解压缩文件(rar或者zip)的实现示例
- 用java压缩文件夹/文件
- 用java压缩文件夹/文件
- 东主楼小集群PBS用法
- java压缩和解压缩Zip、Jar、Gzip文件
- 【Android】ActivityManager结构图
- Bit manipulation
- HDOJ-1823(矩形树,点更新 + 区间查询)