Netbeans Ok but OJ failed test


  • 0
    N

    test case failed on [1,2], custom test case on OJ passed, but failed after submitted on this case

    public class Solution {
        static int min=Integer.MAX_VALUE;
        public int minDepth(TreeNode root) {
            TreeNode runner=root;
            if(root==null) return 0;
            helpMin(root,0);
            return min;
        }
        public void helpMin(TreeNode runner, int depth){
            if(runner==null) return ;
            depth=depth+1;
            if(runner.left==null&&runner.right==null){
                min=Math.min(min,depth);
                return ;
            }
            else{
                helpMin(runner.left,depth);
                helpMin(runner.right,depth);
            }
        }
     }

  • 0

    Did you read the FAQ? You would have to reset your static variable as the static variable preserves its value between test cases.


  • 0
    N

    Thanks a lot! It works now.


Log in to reply
 

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