My code is failing for [1,2] when submitting and not when doing standalone test case


  • 0
    V

    Code:

     static TreeNode addThisToRight=null;
    
        public void flatten(TreeNode root) {
                //addThisToRight=null;
                if(root==null)
                    return;
                flatten(root.right);
                flatten(root.left);
                root.right=addThisToRight;
                root.left=null;
                addThisToRight=root;
            }
    

    My code fails for following input when submitting the code but does not fail when I do stanalone test case using Run Code feature:

    When submitting-

    Input: [1,2]

    Output: [1,null,2,null,0]

    Expected: [1,null,2]

    When doing standalone test case-

    Your input

    [1,2]

    Your answer

    [1,null,2]

    Expected answer

    [1,null,2]


Log in to reply
 

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