https://leetcode.com/problems/binary-tree-level-order-traversal/

func levelOrder(_ root: TreeNode?) -> [[Int]] {
    guard let root = root else { return []}
    var result = [[Int]]()
    var nodes = [root]
    while !nodes.isEmpty {
        result.append(nodes.map{ $0.val })
        nodes = nodes.reduce([], {
            var val = $0
            if let left = $1.left {
                val.append(left)
            }
            if let right = $1.right {
                val.append(right)
            }
            return val
        })
    }
    return result
}

2550FA57-5DD3-4D4B-BC66-3409C328401A