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

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

E307A76A-1B2E-4B7F-9A25-6F1CB5095BEC