dsa · easy
Binary Tree Level Order
GreyOrangeTreeQueueFoundation
Return node values by BFS level. Tree encoding: [val, left, right] or None.
Arguments
root— the binary tree; each node is[val, left, right]orNone
**Example:** [3,[9,None,None],[20,[15,None,None],[7,None,None]]] → [[3],[9,20],[15,7]].
Constraints
Number of nodes in [0, 2000] Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: [3,[9,None,None],[20,[15,None,None],[7,None,None]]] Expected: [[3],[9,20],[15,7]]
Example 2
Input: None Expected: []