Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#144. Binary Preorder Traversal #486

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

mandradem
Copy link

Binary Tree Preorder Traversal Solution for C++ (https://leetcode.com/problems/binary-tree-preorder-traversal/)

Pull Request Template

Description

Problem Summary:
Given the root of a binary tree, return the preorder traversal of its nodes' values.

Example:
Input: root = [1, null,2,3]
Output: [1,2,3]

Constraints:

  • The number of nodes in the tree is in the range [0, 100].
  • -100 <= Node.val <= 100

Approach to the Problem:
In the problem description, it was asked to try to solve the problem iteratively. To be able to do that, using a stack was the best way to solve it. The first step was to evaluate if the given input was an empty vector. If it's empty, return the empty stack. Another case to check for is making sure that the preorder traversal is correct. Preorder Traversal is visiting the root first, then the left subtree, and finally the right subtree is traversed.

List any dependencies that are required for this change.

Put check marks:

Have you made changes in README file ?

  • Added problem & solution under correct topic.
  • Specified Space & Time complexity.
  • Specified difficulty level, tag & Note(if any).

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Please also note any relevant details for your test configuration.

  • Test A
    Input
    root = [1,null,2,3]
    Output
    [1,2,3]
    Expected
    [1,2,3]
  • Test B
    Input
    root = [ ]
    Output
    [ ]
    Expected
    [ ]

Make sure all below guidelines are followed else PR will get Reject:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code so that it is easy to understand
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

Monique Andrade and others added 4 commits June 20, 2024 16:29
…aversal for C++. There was no solution for C++ for this specific problem.
Added the C++ solution link to problem codedecks-in#144
Added the Space and Time-Complexity in the file
Copy link

welcome bot commented Jun 22, 2024

I can tell this is your first pull request! Thank you I'm so honored. 🎉🎉🎉 I'll take a look at it ASAP!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant