[leetcode] MaximumDepthofBinaryTree

/**
* <pre>
* 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.
* </pre>
* */
public class MaximumDepthofBinaryTree {
public 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 1 + Math.max(maxDepth(root.left), maxDepth(root.right));
}
}
}
Xilinx Blockset Counter计数器模块使用及参数配置 本文详细介绍了Simulink中Xilinx Blockset库Counter模块的使用以及参数说明。 阅读详情

相关推荐

从报错到优化:一次Gauss JDBC参数限制排查实录(32767参数上限避坑指南)

本文详细记录了排查GaussDB JDBC驱动因绑定参数数量超过32767上限而抛出`PSQLException`(报错信息为`Tried to send an out-of-range integer as a 2-byte value`)的全过程。文章深入分析了该限制的底层协议原理,并提供了应用层分批查询、使用临时表以及优化业务逻辑等多种解决方案,旨在帮助开发者规避此参数上限陷阱,构建更稳健的数据访问层。

rgv23456789的博客 192

LeetCode maximumDepthOfBinaryTree递归,迭代解法

// Date : 2016.07.26 // Author : yqtao // https://github.com/yqtaowhu/********************************************************************************** * * Given a binary tree, find its maximum de

yqtao的博客 420

binning模式下和normal模式下相同曝光参数相同场景加权亮度差异消除方案优化(一)

摘要:针对ISP参数设置中浮点权重系数需转换为整数的问题,提出整数邻域搜索方案。该方法在浮点最优解附近(±1/±2)进行局部搜索,通过逐阶微调找到误差最小的整数权重组合,避免直接取整导致的误差反弹(误差从0.8%降至0.35%)。方案结合范围约束(1~15)和单调性约束(暗端递减、亮端递增),兼顾计算效率(单图耗时<10ms)与硬件兼容性,显著优于暴力搜索和简单取整,满足工程落地需求。

大熊 56

leetcode_easy】104-MaximumDepthofBinaryTree

/********************************************************************************************************** LeetCode----[easy] 104-MaximumDepthofBinaryTree Given a binary tree, find its maximum depth.

qiki_糖没味儿的程序媛小屋 216

LeetCode104_MaximumDepthofBinaryTree Java题解

题目: 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. 解题: 求最大深度  和前面一题类似  用递归遍历就

u012249528的专栏 685

LeetCode--104--easy--MaximumDepthOfBinaryTree

package com.app.main.LeetCode.tree; import com.app.main.LeetCode.base.TreeNode; /** * 104 * * easy * * https://leetcode.com/problems/maximum-depth-of-binary-tree/ * * Given a binary tree, fi...

huangdingsheng的博客 129

LeetCode 简要日记 455 & 104

今天做了两个简单的小题目,一丢丢难度都没有,就不细说了,记个流水 ###简单的比大小: Assign Cookies 题目描述很长,实际上就是有两个数组,只要s中存在比g大的就算喂饱一个,排个序,挨个比较一下就得到答案了。 public class Solution { public int findContentChildren(int[] g, int[] s) { A...

weixin_33975951的博客 92

leetcode 104_MaximumDepthOfBinaryTree_easy.py

github : https://github.com/CircleZ3791117 #!/usr/bin/env python # -*- coding: utf-8 -*- __author__ = 'circlezhou' ''' Description: Given a binary tree, find its maximum depth. The maximum depth is

CCZ's blog 293

ECMF02-2AMX6的Pin3接地选连接器地还是系统地?一文讲透EMC与ESD设计

在USB接口电路设计中,接地处理直接决定EMC性能和ESD防护效果。连接器地与系统地看似都是地,但在高频和瞬态条件下,它们的电位分布、阻抗特性截然不同。理解两者的本质区别,是硬件工程师进行PCB布局和电路保护设计的基础。ECMF02-2AMX6这类集成共模滤波与ESD保护的多功能器件,其Pin3作为内部二极管的公共参考点,接地路径的选择会影响静电泄放走向、共模噪声抑制能力以及信号完整性。消费电子、工控设备等不同应用场景下,需要结合单点接地或多点接地架构来决策。通过对比连接器地接地与系统地接地的利弊,借助磁珠

weixin_34032792的博客 290

LeetCode题库解答与分析——#104. 二叉树的最大深度MaximumDepthOfBinaryTree

给定一个二叉树,找出其最大深度。二叉树的深度为根节点到最远叶节点的最长路径上的节点数。案例:给出二叉树 [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7返回最大深度为 3 。Given a binary tree, find its maximum depth.The maximum depth is the numbe...

weixin_38385524的博客 212

递归用法总结(二叉树深度为例)

但是面临一个问题,就是当前层数和最大层数,必须要使用全局变量来记录,而在leetcode中,全局变量没法再初始化,所以就不可用。想破脑袋也没想出来怎么解决,后面求助了chatgpt,给的代码也是有这两个全局变量。从最底层开始计数,想来也是非常合理的,其实递归的本质或者从动态规划来说,也是应该自底而上,这样才能拆成更小的独立问题。如上面的二叉树,在3的时候是层1,9的时候就是层2,如果返回了层数就-1,然后使用一个变量记录最大值。提交上去看了下,可以通过但是成绩也不是很理想,应该可以加个字典什么的缓存一下。

fanged的专栏 762

day 16: 二叉树 补卡!

DFS 根本用不到啊 真实的工程中!

nbAnthony的博客 187

LeetcodeLeetcode 刷题

个人刷题LeetCode,不喜勿喷 码云地址 目录 题号 题目 LeetCode code 1 Two Sum leetcode code 2 Add Two Numbers leetcode code 7 Reverse Integer leetcode code ...

chouwuge9548的博客 203

LeetCode知识点总结 - 104

LeetCode 104. Maximum Depth of Binary Tree

m0_59773145的博客 180

leetcode AC rates over 40%按从高到低

Single Number  Total Accepted: 33838 Total Submissions: 73793My Submissions Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algor

phoebe 802

LeetCode题解(三)

LeetCode题解(三) Merge Sorted Array Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note: You may assume that nums1 has enough space (size tha...

weixin_34290352的博客 137

LeetCode 解题方案

下面记录了本人 leetcode 的解题答案 easy 1. Two Sum2. Add Two Numbers7. Reverse Integer104. Maximum Depth of Binary Tree371. Sum of Two Integers409. Longest Palindrome414. Third Maxim...

weixin_33834910的博客 175

LeetCode】Agorithms 题集(一)

Single Number 题目 Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. ...

weixin_30505751的博客 59

边工作边刷题:70天一遍leetcode: day 103

这两天开始重温leetcode经典题,发现再回过头来看很多问题都会有新的心得体会,leetcode的题真是要多过几遍才能融会贯通 Symmetric Tree Problem 这题是道easy题 (曾经linkedin电面时候秒过),但是如果没想清楚只背下题很快就会忘了。下面是题解的code (java) 基本的思路是递归配对。之所以可以用递归的方法是因为镜面对称的二叉树任意配对的no...

weixin_30417487的博客 148

Leetcode深度优先搜索(DFS)总结

深度优先搜索(Depth-First-Search)DFS DFS是leetcode里面的一个大头,也算是一个小难点。 九章的课所讲,能用BFS就不要DFS,第一比较男想,第二可能会导致深度过大占用大量空间。 搜索这种类似枚举的方式,是一定可以解出题目的一种方式,需要重点掌握。 这类题目有一大类是和树有关的: 110. Balanced Binary Tree 104. Maximum...

Bruce_Wang_Lelouch的博客 889

LeetCode //C - 1223. Dice Roll Simulation

Summary: This problem involves counting the number of distinct sequences possible when rolling a die n times, with constraints on the maximum consecutive occurrences of each number. The solution uses dynamic programming to track sequences ending with each

Made in Code 206

电力传输系统中电缆中间接头电-热-力多物理场耦合仿真在Comsol 6.3的应用

利用Comsol 6.3对电缆中间接头进行电-热-力多物理场耦合仿真的方法及其重要性。首先解释了为什么需要进行这种仿真——由于电缆中间接头处存在多种物理现象相互作用,如电流导致的电阻热效应可能引发材料力学性质的变化,最终造成接头松动等问题。接着简述了Comsol 6.3软件的特点,强调其强大的功能和友好的界面能够帮助工程师更好地理解和解决问题。然后逐步讲解了仿真的具体步骤,包括几何建模、材料属性设置、电场、温度场和应力场的配置,最后讨论了如何通过分析仿真结果来优化接头设计,确保电力系统的可靠性和安全性。适用人群:电气工程领域的研究人员和技术人员,尤其是那些从事电力传输设备设计与维护工作的专业人士。使用场景及目标:适用于希望深入了解电缆中间接头内部复杂物理机制的研究者;对于想要提升产品性能的设计工程师来说,可以借助此类仿真手段找到改进设计方案的方向;同时也能为相关行业的质量检测提供理论依据。其他说明:文中提供了大量关于如何在Comsol 6.3中实施仿真的实用技巧,从基本概念到高级特性都有涉及,非常适合有一定基础但想进一步掌握该领域前沿技术的学习者。

基于单片机的仓库智能巡检车的设计

内容包括详细设计文档word版,附带开题报告和相关PPT等文档,供大家参考学习。也可在本博客主页找到单片机设计专栏直接查看哦

上一篇: [leetcode] FindMinimuminRotatedSortedArray2
下一篇: [leetcode] MergeSortedArray
zhangxzhi
博客等级 码龄12年 6粉丝 47原创
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值