leetcode-104. Maximum Depth of Binary Tree
来源:互联网 发布:淘宝宝贝详情页怎么做 编辑:程序博客网 时间:2024/06/06 19:35
leetcode-104. Maximum Depth of Binary Tree
题目:
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 { private int dep = 0; public int maxDepth(TreeNode root) { helper(root,1); return dep; } private void helper(TreeNode root, int i){ if(root ==null) return ; dep = Math.max(dep,i); helper(root.left,i+1); helper(root.right,i+1); }}
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
- 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
- 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
- CentOS 6 安装Rabbitmq(Cluster)
- Android Next 公共组件库:Android-Next
- iOS开发如何跳转到系统设置或功能?
- NOJ 1018 选太子
- SpringMVC中使用Interceptor拦截器
- leetcode-104. Maximum Depth of Binary Tree
- f:Tree
- ts打包代码详解 (ffmpeg)
- zabbix监控mongodb
- 蓝桥杯BASIC_29(高精度加法)
- 场景切换变暗问题
- 通讯录(数据结构)
- 哥德巴赫猜想
- 《从零开始学Swift》学习笔记(Day 64)——Cocoa Touch设计模式及应用之目标与动作