root of a binary tree. List the values of all its nodes in this order: for every node, first its entire left subtree, then the node itself, then its entire right subtree. The rule applies to each subtree just as it does to the whole tree.
If you draw the tree and project the nodes onto a horizontal line, you get exactly this order, left to right.
Return the list of values. For an empty tree, return an empty list.
*The recursive version takes a couple of lines, so try doing it without recursion.*root=tree_node([6, 3, 9, 1, 4, None, 12]) → [1, 3, 4, 6, 9, 12]
First the whole left subtree of the root (1, 3, 4), then the root 6 itself, then the right subtree (9, 12).
root=tree_node([7, None, 5, 8]) → [7, 8, 5]
7 has no left child, so it comes first. Then its right subtree: 5 has a left child 8, which goes before 5.
root=tree_node([]) → []
An empty tree gives an empty list.
Node.val ≤ 1000root=tree_node([6, 3, 9, 1, 4, None, 12])
[1, 3, 4, 6, 9, 12]
Run checks the first 3 tests in your browser. Submit checks all 84 tests on the server, hidden ones included.