Valid Tic-Tac-Toe State
expert · 1135 · lc medium +32 · verified · 34.8% accepted · 587 likes · top 12%
Description
Given a Tic-Tac-Toe board represented as a string array board, return true if and only if this board state is reachable through a sequence of valid moves in a Tic-Tac-Toe game.
The board is a 3 x 3 grid containing the characters ' ', 'X', and 'O', where ' ' denotes an empty cell.
The rules are:
- Players alternate placing their character into an empty ' ' cell.
- The first player always uses 'X'; the second always uses 'O'.
- Characters may only be placed into empty cells, never occupied ones.
- The game ends when three identical non-empty characters occupy any row, column, or diagonal.
- The game also ends when no empty cells remain.
- No moves may be made after the game has ended.
Example 1:
Example 2:
Example 3:
Code