当前位置:网站首页>leetcode 110. Balanced Binary Trees
leetcode 110. Balanced Binary Trees
2022-08-07 06:32:00 【henujolly】
class Solution {
public boolean isBalanced(TreeNode root) {
if(root==null) return true;
return Math.abs(depth(root.left)-depth(root.right))<=1&&isBalanced(root.left)&&isBalanced(root.right);
}
public int depth(TreeNode root){
if(root==null) return 0;
int left=depth(root.left);
int right=depth(root.right);
return Math.max(left,right)+1;
}
}
边栏推荐
- LNK2001 无法解析的外部符号 cuGetErrorName解决
- servlet tutorial 1: environment setup and new servlet project
- Spark基础【运行架构、RDD】
- Scrapy抓取新浪微博
- 归并排序模板
- VoLTE基础自学系列 | 什么是VoLTE中的Silent Redial?它和CSFB什么关系?
- [Acwing Weekly Replay] The 63rd weekly match 20220806
- DOM,SAX,JDOM,DOM4J四种方法对比总结
- #region 与 #endregion 用法(注释代码的折叠)
- How to use the @Async annotation
猜你喜欢
随机推荐
2022 8.3 Simulation
LeetCode 剑指 Offer 09. 用两个栈实现队列
【井字棋】
js高阶函数
jwt 认证机制
The spyder/conda installation package reports an error: conda info could not be constructed. KeyError: 'pkgs_dirs'
[acwing周赛复盘] 第 63 场周赛20220806
内存中的buffer与cache
某音App protobuf协议还原逆向分析
MySQL - index optimization
spyder/conda安装包报错:conda info could not be constructed. KeyError: ‘pkgs_dirs‘
Graph Theory and Network Models - Based on R
grid grid layout
This beta version of Typora is expired
LeetCode 1408. 数组中的字符串匹配
LeetCode 1408. String matching in arrays
10年经验总结:数据分析师7种工具,因果分析划重点!
LeetCode 1163. The last substring lexicographically
开发依赖vs生产依赖
MySQL - 索引优化









