Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Binary Tree Preorder Traversal

XPChallenge Points: 10
levelLevel: Easy

Task:
Given a binary tree, return a list of node values following preorder traversal.
Preorder traversal order:
1. Visit the root node
2. Traverse the left subtree
3. Traverse the right subtree

Example 1:

Input: root = [5,null,10,7]

Output: [5,10,7]

Explanation:

Start at 5 → then right child 10 → then 10’s left child 7.

Example 2:

Input: root = [8,3,12,1,6,null,15,null,null,4,7,14]

Output: [8,3,1,6,4,7,12,15,14]

Example 3:

Input: root = []

Output: []

Example 4:

Input: root = [9]

Output: [9]

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result