题目要求

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.

Note: A leaf is a node with no children.

题目分析及思路

给定一棵二叉树,要求返回它的最大深度。最大深度是指在从根结点到最远叶结点的路径上的结点数。可以使用递归的方法,条件为结点为空。

python代码

# Definition for a binary tree node.

# class TreeNode:

#     def __init__(self, x):

#         self.val = x

#         self.left = None

#         self.right = None

class Solution:

def maxDepth(self, root: TreeNode) -> int:

if not root:

return 0

return 1+max(self.maxDepth(root.left), self.maxDepth(root.right))

LeetCode 104 Maximum Depth of Binary Tree 解题报告的更多相关文章

  1. 【LeetCode】104. Maximum Depth of Binary Tree 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:BFS 方法二:DFS 参考资料 日期 题目 ...

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

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

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

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

  4. [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 long ...

  5. (二叉树 BFS DFS) 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 long ...

  6. 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 long ...

  7. Java [Leetcode 104]Maximum Depth of Binary Tree

    题目描述: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along th ...

  8. 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 long ...

  9. Java for 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 long ...

随机推荐

  1. Python 读取csv的某行

    站长用Python写了一个可以提取csv任一列的代码,欢迎使用.Github链接 csv是Comma-Separated Values的缩写,是用文本文件形式储存的表格数据,比如如下的表格: 就可以存 ...

  2. visio操作

    1.上下标:选中要成为上标的文字,ctrl+shift+"=" 选中要成为下标的文字,ctrl+"="

  3. shell-跳板机便捷增加用户及设置密码

    我的需求: 因网络限制,某些客户机ssh到服务器都得使用跳板机进行转一下,每次帮开帐户,不麻烦不难,但总觉得还可以再优. 不多说,直接放shell.很简单 #!/bin/bash #test add ...

  4. spring data jpa 查询自定义字段,转换为自定义实体

    目标:查询数据库中的字段,然后转换成 JSON 格式的数据,返回前台. 环境:idea 2016.3.4, jdk 1.8, mysql 5.6, spring-boot 1.5.2 背景:首先建立 ...

  5. TI开发环境下载资源

    CCSV7.0 版本下载  http://processors.wiki.ti.com/index.php/Download_CCS IAR7.10 版本下载 https://www.iar.com/ ...

  6. [React] 08 - Tutorial: evolution of code-behind

    有了七篇基础学习,了解相关的知识体系,之后便是系统地再来一次. [React] 01 - Intro: javaScript library for building user interfaces ...

  7. mongodb 建立索引提示异常:WiredTigerIndex::insert: key too large to index, failing 1483

    { "ok" : 0.0, "errmsg" : "WiredTigerIndex::insert: key too large to index, ...

  8. 【SpringCloud微服务实战学习系列】服务治理Spring Cloud Eureka

    Spring Cloud Eureka是Spring Cloud Netflix微服务中的一部分,它基于NetFlix Sureka做了二次封装,主要负责完成微服务架构中的服务治理功能. 一.服务治理 ...

  9. Unity Shader 景深效果

    效果 原理: 开启摄像机的深度模式,将深度保存到一张名为_CameraDepthTexture(Unity5.0之后才有)内置的纹理中. 如果深度在焦点范围内就用原图,否则就用模糊图. Shader: ...

  10. php foreach

    工作半年了我一直以来至知道这样用,foreach($aa as $k=>$r){} 尔今天师父已教我还可以这样用:  foreach($aa as $r){}