✔️ 100% Fastest Swift Solution
\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n *     public var val: Int\n *     public var left: TreeNode?\n *     public var right
```\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n *     public var val: Int\n *     public var left: TreeNode?\n *     public var right: TreeNode?\n *     public init() { self.val = 0; self.left = nil; self.right = nil; }\n *     public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n *     public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n *         self.val = val\n *         self.left = left\n *         self.right = right\n *     }\n * }\n */\nclass Solution {\n    func levelOrder(_ root: TreeNode?) -> [[Int]] {\n        var res: [[Int]] = []\n        var queue: [TreeNode?] = root != nil ? [root] : []\n        var parent\u0421ount = root != nil ? 1 : 0\n        var child\u0421ount = 0\n        var array: [Int] = []\n        var index = 0\n        \n        while parent\u0421ount > 0 {\n            if let node = queue[index] {\n                if node.left != nil {\n                    queue.append(node.left)\n                    child\u0421ount += 1\n                }\n                \n                if node.right != nil {\n                    queue.append(node.right)\n                    child\u0421ount += 1\n                }\n                \n                array.append(node.val)\n                if array.count == parent\u0421ount {\n                    res.append(array)\n                    array = []\n                    parent\u0421ount = child\u0421ount\n                    child\u0421ount = 0\n                }\n                \n                index += 1\n            }\n        }\n        \n        return res\n    }\n    \n}\n```\n\nLet me know in comments if you have any doubts. I will be happy to answer.\n\nPlease upvote if you found the solution useful.
['Swift']