当前位置:网站首页>Niuke-top101-bm36

Niuke-top101-bm36

2022-07-23 16:22:00 A fish that eats cats

public class Solution {
    
    boolean sign = true;
    public boolean IsBalanced_Solution(TreeNode root) {
    
        TreeDepth(root);
        return sign;
    }
    
    public int TreeDepth(TreeNode t){
    
        if(t == null)
            return 0;
        int l = TreeDepth(t.left);
        if(l == -1)
            return -1;
        int r = TreeDepth(t.right);
        if(r == -1)
            return -1;
        if(Math.abs(l - r) > 1){
    
            sign = false;
            return -1;
        }
        return Math.max(l,r) + 1;
    }
}
原网站

版权声明
本文为[A fish that eats cats]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/204/202207231203456011.html