博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【LeetCode从零单排】No104 Maximum Depth of Binary Tree
阅读量:7247 次
发布时间:2019-06-29

本文共 1023 字,大约阅读时间需要 3 分钟。

题目

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 binary tree * public class TreeNode { *     int val; *     TreeNode left; *     TreeNode right; *     TreeNode(int x) { val = x; } * } */public class Solution {    List
deep_list=new ArrayList
(); public int maxDepth(TreeNode root) { if(root==null) return 0; getDepth(root,1); int max=1; for(int i=0;i
max){ max=deep_list.get(i); } } return max; } public void getDepth(TreeNode root,int height){ if(root==null) { deep_list.add(height-1) ; return; } getDepth(root.left,height+1); getDepth(root.right,height+1); }}
代码下载:

/********************************

* 本文来自博客  “李博Garvin“

* 转载请标明出处:

******************************************/

你可能感兴趣的文章
openstack目前个人认为要解决的问题总结,会持续更新
查看>>
我的友情链接
查看>>
Windows-FTP
查看>>
字符集--关于MySQL的中文和乱码问题
查看>>
gamma correction&being linear
查看>>
python 基础 day1
查看>>
iops计算详解
查看>>
new Thread的弊端及Java四种线程池的使用(上)
查看>>
感知机---感知机模型
查看>>
求旋转后的数组Bk中下标与对应数值的乘积的最大值 Rotate Function
查看>>
《大数据的冲击》迷你书
查看>>
经常用Linux 但是你知道它和Unix区别吗?
查看>>
Android编译报R.java报不到的错误解决办法
查看>>
CentOS5.x下安装配置FTP服务器
查看>>
正则数量词及非捕获
查看>>
MPLS 配置步骤
查看>>
Exchange Server 2007灾难恢复(AD+Ex)
查看>>
GRUB2
查看>>
用Java数字签名提供XML安全
查看>>
我的友情链接
查看>>