104. Maximum Depth of Binary Tree
来源:互联网 发布:类似简图的软件 编辑:程序博客网 时间:2024/06/05 08:49
题目:
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.
思路:
看到二叉树的问题,就想到用递归,父节点的深度为两个子节点深度中较大的值再加1.
代码:
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution { public int maxDepth(TreeNode root) { if(root == null){ return 0; }else{ int left = maxDepth(root.left); int right = maxDepth(root.right); if(left > right){ return left+1; }else{ return right+1; } } }}
0 0
- [LeetCode]104.Maximum Depth of Binary Tree
- 104.Maximum Depth of Binary Tree
- 【LeetCode】104.Maximum Depth of Binary Tree
- [Leetcode] 104. Maximum Depth of Binary Tree
- LeetCode --- 104. Maximum Depth of Binary Tree
- LeetCode 104. Maximum Depth of Binary Tree
- 104.Maximum Depth of Binary Tree
- 104. Maximum Depth of Binary Tree
- 104.Maximum Depth of Binary Tree
- 104. Maximum Depth of Binary Tree
- 104. Maximum Depth of Binary Tree
- leetCode 104. Maximum Depth of Binary Tree
- 104. Maximum Depth of Binary Tree
- 104. Maximum Depth of Binary Tree LeetCode
- 104. Maximum Depth of Binary Tree LeetCode
- 104. Maximum Depth of Binary Tree
- LeetCode 104. Maximum Depth of Binary Tree
- leetcode:104. Maximum Depth of Binary Tree
- Mutable关键字
- Android 项目版本的修改
- Tomcat服务器的配置
- linux 安装svn
- uvaoj-232:crossword answer
- 104. Maximum Depth of Binary Tree
- STL_deque
- 关于C和C++一些大神们的讨论
- IOS-52-UITableView中cell分割线左对齐(解决iOS8版本适配问题)
- 什么时候应该使用$scope.$apply()
- GDKOI2016 day 2 Problem 4. 小学生数学题 - 数学题
- 一致性Hash
- 2014年 Thinking of Hardware Design
- tarjan求强联通分量