Python Solution Works for NxN matrix
Got inspired from myCafeBabe\'s solution, you can check on this link : \nhttps://leetcode.com/problems/valid-tic-tac-toe-state/discuss/117580/Straightforward-Ja
Got inspired from myCafeBabe\'s solution, you can check on this link : \nhttps://leetcode.com/problems/valid-tic-tac-toe-state/discuss/117580/Straightforward-Java-solution-with-explaination\n\nSmall enhancement from mine is for loop below, in case size of matrix is N, just need to replace 3 with N \n```\nfrom typing import List\n\n\nclass Solution:\n\tdef validTicTacToe(self, board: List[str]) -> bool:\n\t\tcols, rows = [0] * len(board), [0] * len(board[0])\n\t\tdiagonal, anti_diagonal = 0, 0\n\t\tturn, x_win, o_win = 0, False, False\n\n\t\tfor i in range(len(board)):\n\t\t\tfor j in range(len(board[0])):\n\t\t\t\tif board[i][j] == \'X\':\n\t\t\t\t\tturn += 1\n\t\t\t\t\trows[i] += 1\n\t\t\t\t\tcols[j] += 1\n\t\t\t\t\tif i == j:\n\t\t\t\t\t\tdiagonal += 1\n\t\t\t\t\tif i + j == len(board) - 1:\n\t\t\t\t\t\tanti_diagonal += 1\n\t\t\t\telif board[i][j] == \'O\':\n\t\t\t\t\tturn -= 1\n\t\t\t\t\trows[i] -= 1\n\t\t\t\t\tcols[j] -= 1\n\t\t\t\t\tif i == j:\n\t\t\t\t\t\tdiagonal -= 1\n\t\t\t\t\tif i + j == len(board) - 1:\n\t\t\t\t\t\tanti_diagonal -= 1\n\n\t\tfor idx in range(len(cols)):\n\t\t\tif cols[idx] == 3 or rows[idx] == 3 or diagonal == 3 or anti_diagonal == 3:\n\t\t\t\tx_win = True\n\t\t\t\tbreak\n\t\t\telif cols[idx] == -3 or rows[idx] == -3 or diagonal == -3 or anti_diagonal == -3:\n\t\t\t\to_win = True\n\t\t\t\tbreak\n\n\t\tif (turn != 1 and x_win) or (turn != 0 and o_win):\n\t\t\treturn False\n\n\t\treturn turn == 1 or turn == 0\n```\n
['Python']