Design Tic-Tac-Toe
Design Tic-Tac-Toe
Assume the following rules are for the tic-tac-toe game on an
n x n
board
between two players:
- A move is guaranteed to be valid and is placed on an empty block.
- Once a winning condition is reached, no more moves are allowed.
-
A player who succeeds in placing
n
of their marks in a horizontal, vertical, or diagonal row wins the game.
Implement the
TicTacToe
class:
-
TicTacToe(int n)
Initializes the object the size of the boardn
. -
int move(int row, int col, int player)
Indicates that player with idplayer
plays at the cell(row, col)
of the board. The move is guaranteed to be a valid move.
Follow up:
Could you do better than
O(n2)
per
move()
operation?
Constraints:
-
2 <= n <= 100
-
player is
1
or2
. -
1 <= row, col <= n
-
(row, col)
are unique for each different call tomove
. -
At most
n2
calls will be made tomove
.
Practise: https://leetcode.com/problems/design-tic-tac-toe/
Solution