Given the root of a binary tree, return the preorder traversal of its nodes' values. Pattern focus: Preorder DFS (Root First). Visit root, then left subtree, then right subtree.
root = binary tree root
preorder traversal as an array of node values
Example 1:
Input:
root = [1,null,2,3]
Output:
[1,2,3]
Explanation:
Preorder visits the root before its children.
Example 2:
Input:
root = [1,2,3,4,5,null,6]
Output:
[1,2,4,5,3,6]
Explanation:
The traversal follows root-left-right order.