Maximum Depth of Binary Tree
来源:互联网 发布:windows下dmg转换cdr 编辑:程序博客网 时间:2024/06/06 03:10
/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution { public int maxDepth(TreeNode root) { if(null == root){ return 0; } return 1 + Math.max(maxDepth(root.left),maxDepth(root.right)); }}本题在leetcode中若使用return 1 + maxDepth(root.left)>maxDepth(root.right)?maxDepth(root.left):maxDepth(root.right); 会出现Timeout。可能是由于递归层次太深导致。
0 0
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- 天时地利齐聚 电商巨头掀冷链投资热
- 获取android手机中已安装应用信息以及应用安装和卸载代码集合
- 海水淡化膜:世韩4040海水淡化膜的综合特性
- Smack 结合 Openfire服务器,建立IM通信,发送聊天消息
- OnScrollListener
- Maximum Depth of Binary Tree
- JavaWeb_JavaEE_命名规则
- java垃圾收集方法
- 设计模式19——Command设计模式
- FFmpeg windows平台编译
- android studio使用快捷键
- ArcGIS教程:按属性、形状或位置进行提取
- shell捕捉信号,重定向信号处理函数
- Android常用组件