Leetcode题解 104. Maximum Depth of Binary Tree
来源:互联网 发布:网络创业的机会来源 编辑:程序博客网 时间:2024/05/16 03:28
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.
用递归,随便写了写就过了
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution { public static int maxDepth(TreeNode root) { if(root==null){ return 0; } return findDepth(root,0); } private static int findDepth(TreeNode node,int depth){ int result; if(node==null){ result=depth; return result; } result=max(findDepth(node.left,depth+1),findDepth(node.right,depth+1)); return result; } private static int max(int x,int y){ return x>y?x:y; }}
0 0
- LeetCode题解:Maximum Depth of Binary Tree
- LeetCode题解: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 题解(C++)
- 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
- 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 LeetCode
- 104. Maximum Depth of Binary Tree LeetCode
- 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
- JavaWeb之BaseDao的写法
- 完美解决 Linux 下 Sublime Text 中文输入
- 计算框架MR
- Poj 1797 Heavy Transportation【Dijkstra变形】
- 25匹马,5条赛道,一匹马一个赛道,比赛只能得到5匹马之间的快慢程度,求1,2,3名
- Leetcode题解 104. Maximum Depth of Binary Tree
- 【解决】MappingException提示Association references unmapped class错误
- 佛五戒
- hadoop作业提交和MapReduce基础分析
- LeetCode-335.Self Crossing
- 调整数组顺序使奇数位于偶数前面
- 移动端App与后台服务的对接方案
- 配置 yum 源--怎么也配置不好,最后选择配置本地yum源
- 对 send 和 recv 的改造