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
Input: root = [5,null,10,7]
Output: [5,10,7]
Explanation:
Start at 5 → then right child 10 → then 10’s left child 7.
Input: root = [8,3,12,1,6,null,15,null,null,4,7,14]
Output: [8,3,1,6,4,7,12,15,14]
Input: root = []
Output: []
Input: root = [9]
Output: [9]
Accepted:
Submission: