1275. Find Winner on a Tic Tac Toe Game
On This Page
class Solution:
def tictactoe(self, moves: List[List[int]]) -> str:
n = len(moves)
cnt = [0] * 8
for k in range(n - 1, -1, -2):
i, j = moves[k]
cnt[i] += 1
cnt[j + 3] += 1
if i == j:
cnt[6] += 1
if i + j == 2:
cnt[7] += 1
if any(v == 3 for v in cnt):
return "B" if k & 1 else "A"
return "Draw" if n == 9 else "Pending"