package org.example.leetcodeBook.deepSearch;
// 平衡二叉树
public class IsBalancedSolution {
public boolean isBalanced(InorderTraversalSolution.TreeNode root){
if(root==null)return true;
else
return Math.abs(height(root.left) - height(root.right))<=1 &&
isBalanced(root.left) && isBalanced(root.right);
}
public int height(InorderTraversalSolution.TreeNode root){
if(root==null)return 0;
else return Math.max(
height(root.left),height(root.right)
)+1;
}
}
平衡二叉树
最新推荐文章于 2025-12-26 18:13:00 发布

14万+

被折叠的 条评论
为什么被折叠?



