Swift: Symmetric Tree (+ Test Cases)
swift\nclass Solution {\n    func isSymmetric(_ root: TreeNode?) -> Bool {\n        return check(root, root)\n    }\n    private final func check(_ l: TreeNode?
```swift\nclass Solution {\n    func isSymmetric(_ root: TreeNode?) -> Bool {\n        return check(root, root)\n    }\n    private final func check(_ l: TreeNode?, _ r: TreeNode?) -> Bool {\n        if [l,r].allSatisfy({$0 == nil}) { return true }\n        if l == nil || r == nil { return false }\n        let n = (l?.left, r?.right)\n        return l?.val == r?.val && check(n.0,n.1) && check(n.1,n.0)\n    }\n}\n```\n\n```swift\nimport XCTest\n\n// Executed 2 tests, with 0 failures (0 unexpected) in 0.065 (0.067) seconds\n\nclass Tests: XCTestCase {\n    private let s = Solution()\n    func test1() {\n        let res = s.isSymmetric(.init([1,2,2,3,4,4,3]))\n        XCTAssertEqual(res, true)\n    }\n    func test2() {\n        let res = s.isSymmetric(.init([1,2,2,nil,3,nil,3]))\n        XCTAssertEqual(res, false)\n    }\n}\n\nTests.defaultTestSuite.run()\n```\n\n```swift\npublic 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    public init?(_ array: [Int?]) {\n        var values = array\n        guard !values.isEmpty, let head = values.removeFirst() else { return nil }\n        \n        val = head; left = nil; right = nil\n        \n        var queue = [self]\n        while !queue.isEmpty {\n            let node = queue.removeFirst()\n            if !values.isEmpty, let val = values.removeFirst() {\n                node.left = TreeNode(val)\n                queue.append(node.left!)\n            }\n            if !values.isEmpty, let val = values.removeFirst() {\n                node.right = TreeNode(val)\n                queue.append(node.right!)\n            }\n        }\n    }\n}\n```
['Swift']