Leetcode 104. Maximum Depth of Binary Tree 二叉树的最大高度 解题报告
来源:互联网 发布:2017淘宝必须交保证金 编辑:程序博客网 时间:2024/06/05 03:19
1 解题思想
这道题就是求解二叉树的最大高度,实在是很简单
一个很简单的DFS式的递归就可以
2 原题
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.
3 AC解
/** * 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 dfs(TreeNode root,int deep){ if(root==null) return deep; else return Math.max(dfs(root.left,deep + 1),dfs(root.right,deep + 1)); } public int maxDepth(TreeNode root) { return dfs(root,0); }}
0 0
- 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 [easy]
- [Leetcode] 104. Maximum Depth of Binary Tree 解题报告
- [leetcode]104. Maximum Depth of Binary Tree@Java解题报告
- 【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--二叉树的最大深度
- Leetcode#104. Maximum Depth of Binary Tree(最大二叉树的深度)
- Leetcode 654. Maximum Binary Tree 最大二叉树 解题报告
- Maximum Depth of Binary Tree 求二叉树的高度/深度 @LeetCode
- Maximum Depth of Binary Tree 二叉树的最大深度
- Maximum Depth of Binary Tree 二叉树的最大深度
- Maximum Depth of Binary Tree 二叉树的最大深度
- mvn 编码GBK的不可映射字符
- Android中用代码设置ImageView的src和background
- 分布式系统事务一致性解决方案
- Win10+Qt5 Creator msvc版本+opencv249配置中发现的问题
- Eclipse 发布Web Project到Tomcat的三种方法
- Leetcode 104. Maximum Depth of Binary Tree 二叉树的最大高度 解题报告
- Altium Designer批量把一些元件从顶层换到底层
- 基于HOG-LBP特征融合的头肩检测研究
- 再谈CSS预处理器
- python socket模块属性
- Codeforces Beta Round #42 (Div. 2)-C. Lucky Tickets
- 解决JScrollPane水平滚动条不显示的问题
- yii2 使用数据迁移(或其他接触数据库)时所出现的错误
- while循环-简化分页查询