348. Design Tic-Tac-Toe
Problem
Design a Tic-Tac-Toe game on an n×n board. Return the winner after each move, or 0 if no winner.
Design a Tic-Tac-Toe game that supports:
TicTacToe(n): Initialize an n×n board.move(row, col, player): Player 1 or 2 makes a move at (row, col). Return the winner (1 or 2), or 0 if no winner yet.
A player wins if they have n tokens in a row: horizontally, vertically, or diagonally.
Examples
Input: [["TicTacToe","move","move","move","move","move","move","move"],[[3],[0,0,1],[0,2,2],[2,2,1],[1,1,2],[2,0,1],[1,0,2],[2,1,1]]]
Output: [null,0,0,0,0,0,0,1]
Input: [["TicTacToe","move","move","move","move","move","move","move"],[[3],[0,0,1],[0,2,2],[2,2,1],[1,1,2],[2,0,1],[1,0,2],[2,1,1]]]
Output: [null,0,0,0,0,0,0,1]
Hints
Track row and column counts for each player.
Track diagonal and anti-diagonal counts.
After each move, check if the current player has won.
Related Problems
348. Design Tic-Tac-Toe
Design a Tic-Tac-Toe game on an n×n board. Return the winner after each move, or 0 if no winner.