Why my output is wrong?


  • 0
    S

    Hi All,
    I define the toString as below for TreeLinkNode:

     public String toString() {
            return "TreeLinkNode [val=" + val + ", " + (left != null ? "left=" + left.val + ", " : "")
                + (right != null ? "right=" + right.val + ", " : "") + (next != null ? "next=" + next.val : "") + "]";
     }
    

    Here is the result:

    • Input: {1,2,3,4,#,#,5}
    • Output: {1,#,2,3,#,4,#}
    • Expected: {1,#,2,3,#,4,5,#}

    And here is the my debug result in the eclipse:

    • TreeLinkNode [val=1, left=2, right=3, ]
    • TreeLinkNode [val=2, left=4, next=3]
    • TreeLinkNode [val=3, right=5, ]
    • TreeLinkNode [val=4, next=5]
    • TreeLinkNode [val=5, ]

    What's wrong with my result?


Log in to reply
 

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