tutorialcup
Find Winner on a Tic Tac Toe Game Leetcode Solution
The problem Find Winner on a Tic Tac Toe Game Leetcode Solution asks us to find out the winner of a tic tac toe game. The problem provides us with an array or vector of moves made by the players. We need to go through the moves and judge who wins the game. The outcome of the game can be won, draw, or pending. In cases, when any one of them wins the game, we return A or B. But before judging the game, we must be aware of the rules of this specific version of Tic Tac Toe.
- Players can only make moves on squares that have not been utilized already.
- The first player A always places "X" characters, while the second player B always places "O" characters.
- "X" and "O" characters are always placed into empty squares. One should never use squares that have already been utilized.
- The game ends when there are 3 of the same (non-empty) character filling any row, column, or diagonal.
- The game also ends if all squares are non-empty. In some cases, both of them do not win and end up in a draw.
- No more moves can be played if the game is over. If there are some moves left, the verdict is "Pending".
- Player "A" makes the first move and then alternate turns are used by both the players.
Let's take a look at a few examples.
moves = ,,,,]
"A"
Explanation: As shown above in the figure, the player with the "X" wins the game. A always starts the game, thus the winner is also "A".
Approach
www.tutorialcup.com/leetcode-solutions/find-winner-on-a-t...
Find Winner on a Tic Tac Toe Game Leetcode Solution
The problem Find Winner on a Tic Tac Toe Game Leetcode Solution asks us to find out the winner of a tic tac toe game. The problem provides us with an array or vector of moves made by the players. We need to go through the moves and judge who wins the game. The outcome of the game can be won, draw, or pending. In cases, when any one of them wins the game, we return A or B. But before judging the game, we must be aware of the rules of this specific version of Tic Tac Toe.
- Players can only make moves on squares that have not been utilized already.
- The first player A always places "X" characters, while the second player B always places "O" characters.
- "X" and "O" characters are always placed into empty squares. One should never use squares that have already been utilized.
- The game ends when there are 3 of the same (non-empty) character filling any row, column, or diagonal.
- The game also ends if all squares are non-empty. In some cases, both of them do not win and end up in a draw.
- No more moves can be played if the game is over. If there are some moves left, the verdict is "Pending".
- Player "A" makes the first move and then alternate turns are used by both the players.
Let's take a look at a few examples.
moves = ,,,,]
"A"
Explanation: As shown above in the figure, the player with the "X" wins the game. A always starts the game, thus the winner is also "A".
Approach
www.tutorialcup.com/leetcode-solutions/find-winner-on-a-t...