Small 2ms java solution. Any comments?


  • 1
    S
    public boolean isBalanced(TreeNode root) {
        return -1 != check(root);
    }
    private int check(TreeNode root){
        if (root == null) return 0;
        int l = check(root.left);
        int r = check(root.right);
        return l == -1 || r == -1 || Math.abs(l-r) > 1 ? -1 : 1 + Math.max(l,r);
    }

  • 0
    L

    Good but same as many previous solutions.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.