My code fails in this test case {1,2}, {1,#,2} .. what is # ??


  • 0
    E

    {
    public string getBFDisplay(TreeNode node)
    {
    if (node == null)
    return "";
    StringBuilder sb = new StringBuilder();

            Queue<TreeNode> queue = new Queue<TreeNode>();
            TreeNode current = null;
    
            
            queue.Enqueue(node);
    

    return sb.ToString();
    }
    }


  • 0
    L

    "#" represents an empty TreeNode


  • 0
    M

    Close, # represents the end of the line. The give node is null, and all nodes that could descend through that node are not included in the list. This is in contrast with some other methods of storing a tree, such as with an array of TreeNodes with the children of node n at indices 2n+1 and 2n+2, with those indices being null if no node exists there.


Log in to reply
 

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