# Leetcode 794 - Valid Tic-Tac-Toe State

Note:

• Don’t use DFS coz X or O is not to be placed along some path. It can be just random.
• Find out the pattern!
• If Both X and O win, it’s false.
• If there are more Os than Xs, it’s false.
• If X wins but there are same number of Xs and Os, it’s false.
• Likewise, if O wins but there are more Xs than Os, it’s false.

Question:

Given a Tic-Tac-Toe board as a string array board, return true if and only if it is possible to reach this board position during the course of a valid tic-tac-toe game.

The board is a 3 x 3 array that consists of characters ' ', 'X', and 'O'. The ‘ ‘ character represents an empty square.

Here are the rules of Tic-Tac-Toe:

• Players take turns placing characters into empty squares ‘ ‘.
• The first player always places ‘X’ characters, while the second player always places ‘O’ characters.
• ‘X’ and ‘O’ characters are always placed into empty squares, never filled ones.
• The game ends when there are three of the same (non-empty) character filling any row, column, or diagonal.
• The game also ends if all squares are non-empty.
• No more moves can be played if the game is over.

Example:

Code: