Swift solution
\nclass Solution {\n    var countX = 0\n    var countO = 0\n\n    func validTicTacToe(_ board: [String]) -> Bool {\n        guard isValidCount(board), isMeeting
```\nclass Solution {\n    var countX = 0\n    var countO = 0\n\n    func validTicTacToe(_ board: [String]) -> Bool {\n        guard isValidCount(board), isMeetingWinningCriteria(board) else {\n            return false\n        }\n      return true        \n    }\n    \n    private func isMeetingWinningCriteria(_ board: [String]) -> Bool {\n        // the idea behind this is if "X" is the winner then the count of X == count of Y + 1\n        // and if O is winner, then the count of Y == count of X\n        // We need to check this for all rows, columns and diagonals\n        return isValidRow(board) && isValidColumn(board) && isValidDiagonal(board)\n    }\n    \n    private func isValidRow(_ board: [String]) -> Bool {\n        for i in 0..<3 {\n            var countX = 0\n             var countO = 0\n            let row = board[i]\n            for j in 0..<3 {\n                 let index = row.index(row.startIndex, offsetBy: j)\n                let ch = row[index]\n                if ch == "X" {\n                    countX += 1\n                }\n                else if ch == "O" {\n                    countO += 1\n                }\n            }\n             if !validate(countX, countO) {\n                return false\n            }\n        }\n        return true\n    }\n    \n    private func isValidColumn(_ board: [String]) -> Bool {\n        for i in 0..<3 {\n            var countX = 0\n            var countO = 0\n            for j in 0..<3 {\n                let row = board[j]\n                let index = row.index(row.startIndex, offsetBy: i)\n                let ch = row[index]\n                if ch == "X" {\n                    countX += 1\n                } else if ch == "O" {\n                    countO += 1\n                }\n            }\n            if !validate(countX, countO) {\n                return false\n            }\n        }\n        return true\n    }\n    \n    private func isValidDiagonal(_ board: [String]) -> Bool {\n         var countX = 0\n         var countO = 0\n        for i in 0..<3 {\n          let row = board[i]\n            let index = row.index(row.startIndex, offsetBy: i)\n                let ch = row[index]\n                if ch == "X" {\n                    countX += 1\n                } else if ch == "O" {\n                    countO += 1\n                }\n        }\n            \n        if !validate(countX, countO) {\n               return false\n        }\n        \n        countX = 0\n        countO = 0\n        for i in (0..<3).reversed() {\n               let row = board[2-i]\n                let index = row.index(row.startIndex, offsetBy: i)\n                let ch = row[index]\n                if ch == "X" {\n                    countX += 1\n                } else if ch == "O" {\n                    countO += 1\n                }\n        }\n        return validate(countX, countO)\n    }\n    \n    private func validate(_ countX: Int, _ countO: Int) -> Bool {\n        if countX == 3 {\n               return self.countX - 1 == self.countO\n         } else if countO == 3 {\n            return self.countX == self.countO\n        }\n        return true\n    }\n    \n    private func isValidCount(_ board: [String]) -> Bool {\n        board.forEach { row in\n            row.forEach { char in\n                if char == "X" {\n                    countX += 1\n                } else if char == "O" {\n                    countO += 1\n                }\n            }\n        }\n        return countX == countO || countX - 1 == countO\n    }\n}\n```
[]