104. 二叉树的最大深度

104. Maximum Depth of Binary Tree

题目描述

给定一个二叉树,找出其最大深度。

二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。

说明: 叶子节点是指没有子节点的节点。

LeetCode104. Maximum Depth of Binary Tree

示例:

给定二叉树 [3,9,20,null,null,15,7],
```
3
/ \
9 20
/ \
15 7
```
返回它的最大深度 3。

Java 实现

class TreeNode {
int val;
TreeNode left;
TreeNode right; TreeNode(int x) {
val = x;
}
} public class Solution {
public int maxDepth(TreeNode root) {
if (root == null) {
return 0;
}
return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1;
}
}

相似题目

参考资料

LeetCode 104. 二叉树的最大深度(Maximum Depth of Binary Tree)的更多相关文章

  1. [Swift]LeetCode104. 二叉树的最大深度 | Maximum Depth of Binary Tree

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

  2. 【Leetcode】【Easy】Maximum Depth of Binary Tree

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

  3. 【leetcode刷题笔记】Maximum Depth of Binary Tree

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

  4. 【easy】104. Maximum Depth of Binary Tree 求二叉树的最大深度

    求二叉树的最大深度 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; ...

  5. leetcode 104 Maximum Depth of Binary Tree二叉树求深度

    Maximum Depth of Binary Tree Total Accepted: 63668 Total Submissions: 141121 My Submissions Question ...

  6. LeetCode Javascript实现 258. Add Digits 104. Maximum Depth of Binary Tree 226. Invert Binary Tree

    258. Add Digits Digit root 数根问题 /** * @param {number} num * @return {number} */ var addDigits = func ...

  7. [LintCode] Maximum Depth of Binary Tree 二叉树的最大深度

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

  8. LeetCode 104. Maximum Depth of Binary Tree C++ 解题报告

    104. Maximum Depth of Binary Tree -- Easy 方法 使用递归 /** * Definition for a binary tree node. * struct ...

  9. 【LeetCode】104. Maximum Depth of Binary Tree (2 solutions)

    Maximum Depth of Binary Tree  Given a binary tree, find its maximum depth. The maximum depth is the ...

随机推荐

  1. 64位内核开发第四讲,查看SSDT表与showSSDT表

    目录 SSDt表与ShadowSSDT表的查看. 一丶SSDT表 1.什么是SSDT表 2.查看步骤 二丶ShadowSSDT表 1.什么是ShadowSSDT表 2.如何查看. 三丶工具介绍 SSD ...

  2. Java 合并PDF文件

    处理PDF文档时,我们可以通过合并的方式,来任意合并几个不同的PDF文件,使我们方便的存储和管理文档.例如,在做毕业设计的时候,封面和论文正文往往是两个PDF文档,但是,上交电子档的时候,需要合二为一 ...

  3. P5049 旅行(数据加强版)(基环树)

    做法 把环找出来,如果在环上(u,v)两点的时候,u的其他子树都走完了,v上第一个还有除v存在的子树没走完的 祖先,祖先的最小子节点小于v,则回去 Code #include<bits/stdc ...

  4. SpringCloud:Ribbon负载均衡

    1.概述 Spring Cloud Ribbon是基于Netflix Ribbon实现的一套客户端       负载均衡的工具. 简单的说,Ribbon是Netflix发布的开源项目,主要功能是提供客 ...

  5. JS 读取 获取 cookie

    alert(document.cookie); cookie 只能获取当前域名的cookie, 该页面的其他域名的获取不了的.

  6. gstreamer的gst-inspect 和gst-launch

    用gstreamer架构做对媒体开发时,gst-inspect 和gst-launch是两个非常使用的小工具,前者是用于查询库中已经包含的所有element以及他们的详细信息,后者用于快速构建一条pi ...

  7. 手写HashMap实践

    1.什么是HashMap 2.源码分析 3.手写实现 4.不足 一.什么是HashMap hash散列 将一个任意长度通过某种算法(hash函数算法)换成一个固定值 map: 地图x,y 存储 总结: ...

  8. ISO/IEC 9899:2011 条款6.7.1——存储类说明符

    6.7.1 存储类说明符 语法 1.storage-class-specifier: typedef extern static _Thread_local auto register 约束 2.在一 ...

  9. MySQL创建双主键

    如下: CREATE TABLE `loginlog` ( `id` ) unsigned zerofill NOT NULL AUTO_INCREMENT COMMENT '主键编号', `IP` ...

  10. iOS 控制输入框的字数?(textFliedView,textFlied等)

    //控制输入框的字数 - (void)textViewDidChange:(UITextView *)textView { NSInteger number = [textView.text leng ...