Find Winner on a Tic Tac Toe Game LeetCode solution in Python
1class Solution:2def tictactoe(self, moves: List[List[int]]) -> str:3wins = [4[(0, 0), (0, 1), (0, 2)],5[(1, 0), (1, 1), (1, 2)],6[(2, 0), (2, 1), (2, 2)],7[(0, 0), (1, 0), (2, 0)],8[(0, 1), (1, 1), (2, 1)],9[(0, 2), (1, 2), (2, 2)],10[(0, 0), (1, 1), (2, 2)],11[(0, 2), (1, 1), (2, 0)],12]1314def checkWin(S):15for win in wins:16flag = True17for pos in win:18if pos not in S:19flag = False20break21if flag:22return True23return False2425A, B = set(), set()26for i, (x, y) in enumerate(moves):27if i % 2 == 0:28A.add((x, y))29else:30B.add((x, y))3132if checkWin(A):33return "A"34elif checkWin(B):35return "B"3637return "Draw" if len(moves) == 9 else "Pending"