Swift 20ms
\n func levelOrder(_ root: TreeNode?) -> [[Int]] {\n        guard root != nil else { return [] }\n        var result: [[Int]] = []\n        \n        var queue:
```\n func levelOrder(_ root: TreeNode?) -> [[Int]] {\n        guard root != nil else { return [] }\n        var result: [[Int]] = []\n        \n        var queue: [TreeNode?] = []\n        queue.append(root)\n        \n        while(!queue.isEmpty) {\n            var count = queue.count - 1\n            var temp: [Int] = []\n             while(count >= 0) {\n               if let node = queue.removeFirst() {\n                   temp.append(node.val)\n                   count -= 1\n                   if let left = node.left { queue.append(left) }\n                   if let right = node.right { queue.append(right) }\n               }\n            }\n            \n            result.append(temp)\n        }\n        \n        return result\n    }\n```
[]