Help: Got a "Internal Error" without any detail information


  • 0
    S
    public class Solution {
    public boolean isBalanced(TreeNode root){
        int hi = height(root);
        boolean res = hi!=-1;
        return res;
    }
    
    private int height(TreeNode subtree) {
        //if this subtree is balanced return its height, otherwise return -1;
        if (subtree == null) return 0;
        if (subtree.left==null && subtree.right==null) {
            return 1;
        }
        int a,b;
        if (subtree.left!=null) {
            a = height(subtree.left);
        } else {
            a = 0;
        }
        
        if (subtree.right!=null) {
            b = height(subtree.right);
        } else {
            b = 0;
        }
        
        if (a==-1 || b == -1) return -1;
        else {
            if (Math.abs(a-b)<=1) {
                return Math.max(a, b) + 1;
            } else {
                return -1;
            }
        }
    }
    

    }

    This is my code


  • 0
    C

    I got this on another problem right now. I moved the code to my linux env and compiled, and everything worked out ok. Not sure what is going on with OJ.


Log in to reply
 

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