[Leetcode] 104. Maximum Depth of Binary Tree

小程序HTTPS证书配置踩坑记:为什么Android访问失败而iOS正常? 本文深入剖析了小程序开发中常见的跨平台网络问题:Android访问HTTPS接口失败而iOS正常。核心原因在于服务器(如Nginx)HTTPS证书链配置不完整,Android系统对此校验严格,而iOS相对宽松。文章提供了从问题诊断、使用在线工具检测到修复Nginx证书链配置的完整解决方案,并总结了HTTPS部署的最佳实践,帮助开发者从根本上避免此类“玄学”故障。 阅读详情

Description:


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.

Example:

Given binary tree [3,9,20,null,null,15,7],

    3
   / \
  9  20
    /  \
   15   7

return its depth = 3.

 

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
class Solution {
    public int maxDepth(TreeNode root) {
        if (root == null){
            return 0;
        }else if (root.left == null && root.right == null) {
            return 1;
        }else {
            int left = maxDepth(root.left);
            int right = maxDepth(root.right);
            return 1 + (Math.max(left,right));
        }           
    }
}

 

使用思路就是用递归不停的取当前所在element左边以及右边的最大值

return 1 + max(n左,n右)

详解Pytorch求导 本文主要详解Pytorch求导,希望能对学习Pytorch的同学有所帮助。 文章目录 1. pytorch求导问题 2. pytorch三大类求导代码示例 2.1 标量求导 2.2 向量求导&矩阵求导 阅读详情

相关推荐

Mac mini 24G大模型推理内存瓶颈与优化实战

统一内存架构(UMA)是Apple Silicon的核心特性,其内存带宽固定、CPU/GPU/神经引擎共享物理池,导致大模型推理时易出现带宽争抢而非容量不足。Q4_K_M量化、KV Cache动态膨胀、Tokenizer缓存失控及Metal Shader编译开销共同构成内存消耗黑洞。技术价值在于将‘OOM Killed: 9’从玄学错误转化为可建模的资源调度问题;典型应用场景包括本地LLM部署、边缘AI推理与轻量RAG验证;本文聚焦M系列芯片下24GB UMA的实际承载边界与不换硬件的确定性优化路径,涵盖G

weixin_33461476的博客 214

LeetCode 104. Maximum Depth of Binary Tree 题解

本题是二叉树的基本问题,主要考察对二叉树遍历和递归的理解。递归深度优先搜索:代码简洁易懂,但在树深度较大时可能会遇到栈溢出的问题。迭代深度优先搜索:避免了递归的栈溢出问题,适用于深度较大的树。广度优先搜索:层次清晰,易于理解,且在树宽度较大时表现较好。在实际应用中,可根据树的具体情况选择合适的方法。对于一般的二叉树,递归方法通常是最直观和简洁的选择。

cannonjinx的博客 4588

STM32硬件SPI驱动ADS1255/1256避坑指南:从Cube MX配置到稳定采样实战

本文详细解析了使用STM32硬件SPI驱动高精度ADC芯片ADS1255/1256的完整流程与关键陷阱。重点阐述了Cube MX中SPI模式(必须为CPOL=1, CPHA=1)、数据帧格式(MSB First)及波特率(建议从256kHz起)的正确配置,并提供了分步读写时序的代码实现与逻辑分析仪调试方法,帮助开发者避开常见坑点,实现稳定可靠的高精度数据采样。

weixin_29193259的博客 363

LeetCode 104. Maximum Depth of Binary Tree和111. Minimum Depth of Binary Tree 递归

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.

老夫编代码就是一把梭 594

Java面试题大全(2025版)

== 对于基本类型来说是值比较,对于引用类型来说是比较的是引用;而 equals 默认情况下是引用比较,只是很多类重新了 equals 方法,比如 String、Integer 等把它变成了值比较,所以一般情况下 equals 比较的是值是否相等。

2401_89221704的博客 2442

104报文解析工具

可选择包含报文的文本文件或日志文件进行解析,可选择按条数范围或时间范围,输出结果可以在报文解析显示区,也可以输出到文件。可以对文本内容的报文文件进行高级分析,包括遥信遥测等通讯数据的具体信息,通讯帧的统计,通讯次数的统计,各种错误的分析,报文的定位功能,传输的文件具体内容等。输入完成后点击工具栏的解析报文按钮或使用右键菜单的解析就可以对报文进行解析。在报文输入区输入待解析报文并解析后,解析结果就显示在报文解析显示区和报文定位展示区及报文定位条目区。当有多条报文解析后,可以通过报文列表树具体定位某条报文。

XZHOUMIN的博客 5952

Leetcode 104 Maximum Depth of Binary Tree

leetcode104 题目描述 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 ...

qq_43271202的博客 234

【开关电源篇】整流及其滤波电路的工作原理和设计指南-超简单解读

半波整流是一种利用二极管的单向导通特性,将交流电转换为直流电的基础电路。它通过“切除”交流电的半个周期,仅保留另外半个周期来实现整流。1 开关电源超快学习思路点击跳转1.1开关电源的原理、结构和实物入门篇-超简单解读点击跳转1.2开关电源的EMI输入电路-超简单解读点击跳转倍压整流适用于需要高电压、小电流的特殊场合,通过电容充放电实现电压倍增。

2301_81299416的博客 2931

闯关leetcode——104. Maximum Depth of Binary Tree

最简单的办法就是遍历这棵树,对于每个节点,返回它的最长子树的深度+1。对于nullptr,返回0。这种题都是递归思想。

方亮的专栏 899

STM32控制气泵和电磁阀实现

2、mos管的选型:mos管选择主要注意两个参数即可,一是导通的电流,二是耐压值,并且常用NMOS管,根据要求,气泵和电磁阀供电电压为12V,所以选择的mos管耐压值要大于12V,这里选用耐压值为30V的MOS管,并且导通电流为5.8A,如下图。1、气泵和电磁阀的开和关均为开关量,实现控制方法有多种,比如继电器,但是继电器动作有噪声且体积较大,更好的方法为使用mos管。使用STM32控制气泵和电磁阀的开和关,气泵和电磁阀的供电电压为12V。最终实现单片机控制气泵和电磁阀的开和关。

jacklood的博客 1万+

43、FMCW雷达高度计仿真

本文介绍了FMCW雷达高度计的波形级建模与仿真过程,重点模拟了着陆和倾斜两种飞行场景以评估其性能。通过结合高程数据和飞行轨迹构建雷达场景,使用自定义信号处理器分析IQ样本并估计高度。结果表明,该高度计在多数情况下满足性能要求,但也存在误差较大的点,提出了地面检测算法优化的潜在方向。

neovim7hacker的博客 136

LeetCode题解-104-Maximum Depth of Binary Tree

尽管写LeetCode解答主要是为了自己整理思路,但是如果对您也正好有帮助,请点个赞给菜鸟一点鼓励吧 :-) 原题 解法分析 解法1使用递归法; 解法2参考了别人的思路,为迭代法,类似于广度优先搜索; 自己的迭代法使用了后序遍历来统计树的深度,较为繁琐,没有参考意义。 解法1 解法分析 递归计算左子树的深度与右子树的深度,那么树的深度为两个子树中深度

WangT443的博客 632

影楼精修-高低频磨皮算法解析

本文介绍了像素蛋糕软件中的高低频磨皮算法原理及实现思路,抛砖引玉。

Trent1985的专栏 2262

【LeetCode】104. Maximum Depth of Binary Tree

我的个人微信公众号:Microstrong 微信公众号ID:MicrostrongAI 微信公众号介绍:Microstrong(小强)同学主要研究机器学习、深度学习、计算机视觉、智能对话系统相关内容,分享在学习过程中的读书笔记!期待您的关注,欢迎一起学习交流进步! 知乎主页:https://www.zhihu.com/people/MicrostrongAI/activities Git...

Microstrong 583

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

LeetCode104.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. Note: A leaf is a node with no children. Example: Given binary tree [3,9,20,null,null,15,7],

qq_41704019的博客 329

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

LeetCode 104. Maximum Depth of Binary Tree

LeetCode 104. Maximum Depth of Binary Tree (Easy) 主要知识点:树、BFS、DFS、递归、迭代;优先级:5

温迪今天刷题了吗 444

Leetcode104. Maximum Depth of Binary Tree

Leetcode104. 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 nod...

magic_jiayu的博客 276

Leetcode 104. Maximum Depth of Binary Tree

Leetcode 104. Maximum Depth of Binary Tree 题目描述:找出二叉树的最大深度。 题目链接:Leetcode 104. Maximum Depth of Binary Tree 思路:递归的做法就是不断返回二叉树的左子树右子树深度比较大的那一个。 迭代的做法就是,用hashmap记录每个节点的深度,然后不断遍历的过程中更新ans,最后加上根节点的深度。 ...

Za七杂⑧ 218

LeetCode104—Maximum Depth of Binary Tree

LeetCode104—Maximum Depth of Binary Tree求二叉树的深度。

上善若水 860

leetcode【104】Maximum Depth of Binary Tree

写在最前面:null   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 th...

ssjdoudou的博客 2万+

LeetCode力扣 104. 二叉树的最大深度 Maximum Depth of Binary Tree 题解代码 JavaScript

问题https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/submissions/ 练习使用JavaScript解答 /** * Definition for a binary tree node. * function TreeNode(val) { * this.val = val; * this.left = this.right = null; * } */ /** * @param {Tre.

Coding home - 漂流瓶jz 607

【leetcode c++】104 Maximum Depth of Binary Tree

Maximum Depth of Binary Tree   Given a binary tree, find its maximumdepth. The maximum depth is the number of nodesalong the longest path from the root node down to the farthest leaf node.   给一棵二

lif的博客 496

[LeetCode]104. Maximum Depth of Binary Tree

[LeetCode]104. Maximum Depth of Binary Tree题目描述思路深搜,节点为NULL返回0,其余比较左右子树大小,返回大值代码/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *ri

Lcharon的博客 2845

leetcode104. 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. Note: A leaf is a node with no childr...

中华小当家的博客 261

LeetCode:104. Maximum Depth of Binary Tree

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 no...

Wisimer 188
上一篇: [Leetcode] 693. Binary Number with Alternating Bits
下一篇: [Leetcode] 521. Longest Uncommon Subsequence I
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值