解决最大深度就是看左/右子树最深能到多深,那么就直接设两个成员变量作为两者的深度,然后直接调用Math.max(a,b)函数,然后就知道a,b哪个更大,最后要注意得到的值要+1,应该一开始定义树的深度为1class Solution { public int maxDepth(TreeNode root) { if(root==null){ return 0; } else{ int leftTreeDepth=maxDepth(root.left); int rightTreeDepth=maxDepth(root.right); return java.lang.Math.max(leftTreeDepth,rightTreeDepth)+1; } } }
解题思路
本网页所有视频内容由 imoviebox边看边下-网页视频下载, iurlBox网页地址收藏管理器 下载并得到。
ImovieBox网页视频下载器 下载地址: ImovieBox网页视频下载器-最新版本下载
本文章由: imapbox邮箱云存储,邮箱网盘,ImageBox 图片批量下载器,网页图片批量下载专家,网页图片批量下载器,获取到文章图片,imoviebox网页视频批量下载器,下载视频内容,为您提供.
阅读和此文章类似的: 全球云计算