Tree: Preorder Traversal

Sort by

recency

|

83 Discussions

|

  • + 0 comments

    Ridiculously easy. Note that python optimizes tail recursive loops so this isn't an inefficient use of recursion.

    def preOrder(root):
        if root is None:
            return
        print(root.info, end=' ')
        preOrder(root.left)
        preOrder(root.right)
    
  • + 0 comments

    Why is this considered an advanced level challenge?

    I'm not even sure what the challenge was supposed to be. It felt more like a introduction to trees tutorial question.

  • + 0 comments

    Why is the php so messed up? why doesn't it make sense compared to python and js ?

  • + 0 comments
    void preOrder(Node *root) {
    
                if (root == nullptr){
                return;
        }
    
        std::cout << root->data << " ";
        preOrder(root->left);
        preOrder(root->right);}
    
    }
    
  • + 0 comments

    Why is the C++ 14 solution template formulated in such a weird way that you cannot include additional libraries (such as stack for this question)? The C++ 11 and 20 templates are totally fine. I wish the solution templates are all standardized like Leetcode does.