Why the result is wrong?

  • 1

    My code as follows:
    Test case is :{2,1,3}
    I tried in eclipse, it works very well ,however, here return false. I don't know why?

    public class Solution {
    public static boolean isbalanced = true;
    public boolean isBalanced(TreeNode root) {
            if(null == root)
            return true;
            return isbalanced;
    public int getdepth(TreeNode root, int dep){
        if(root ==null)
        return dep;
        int left = getdepth(root.left,1+dep);
        int right = getdepth(root.right,1+dep);
            isbalanced= false;
        return Math.max(left,right);

  • 1

    You should not use "static" in "public static boolean isbalanced = true;" .

  • 0

    Still confused about it. Could spare time to tell me why can't add static here? Thx!

  • 0

    The same question, should you please give us some details about it?

Log in to reply

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