Swift BFS
The idea here is to simply proceed our level order traverse left to right but append items to end or to begin of sub arrays following current swapping direction
The idea here is to simply proceed our level order traverse left to right but append items to end or to begin of sub arrays following current swapping direction.\n```\nclass Solution {\n    private enum Direction {\n        case right\n        case left\n    }\n\n    func zigzagLevelOrder(_ root: TreeNode?) -> [[Int]] {\n        var ans = [[Int]]()\n        guard let root = root else { return ans }\n        var queue = [root]\n        var direction = Direction.left\n        while !queue.isEmpty {\n            let count = queue.count\n            var sub = [Int]()\n            for i in 0..<count {\n                let curr = queue.removeFirst()\n                switch direction {\n                case .right:\n                    sub.append(curr.val)\n                case .left:\n                    sub.insert(curr.val, at: 0)\n                }\n                if let right = curr.right {\n                    queue.append(right)\n                }\n                if let left = curr.left {\n                    queue.append(left)\n                }\n            }\n            ans.append(sub)\n            direction = direction == .left ? .right : .left\n        }\n        return ans\n    }\n}\n```
['Breadth-First Search', 'Swift']