Tests are broken, prove bellow


  • -1
    M

    Seems like compiling engine here is broken:

    for the following code:

    /**
     * Definition for a binary tree node.
     * public class TreeNode {
     *     int val;
     *     TreeNode left;
     *     TreeNode right;
     *     TreeNode(int x) { val = x; }
     * }
     */
    public class Solution {
        static int depth = 0;
        public int maxDepth(TreeNode root) {
            if (root == null) return 0;
            goDeeper(root,1);
            return depth;
    }
    
    public void goDeeper(TreeNode node, int lvl) {
        if(lvl > depth)
            depth++;
        if(node.left!=null){
            goDeeper(node.left, lvl+1);
        }
        if(node.right!=null){
            goDeeper(node.right, lvl+1);
        }
    }
    

    }

    I do have wrong answer for testcase:
    Input:
    [0,0,0,0,null,null,0,null,null,null,0]
    Output:
    5
    Expected:
    4

    When i literally copy the test case and run code manually I do have:
    Your input

    [0,0,0,0,null,null,0,null,null,null,0]
    Your answer

    4
    Expected answer

    4
    Runtime: 0 ms

    Can anybody explain that?


  • 0
    M

    Just launched it in java and works fine. Definetely tests are broken.


  • 0

    No, it's definitely your code that's broken. You explicitly request the value of depth to be reused in later test cases, which is of course bad. That's your fault. Besides, that's even covered in the FAQ.


Log in to reply
 

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