794. Valid Tic-Tac-Toe State Medium

@problem@discussion
#Array#String



1/**
2 * [794] Valid Tic-Tac-Toe State
3 *
4 * 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.
5 * The board is a 3 x 3 array that consists of characters ' ', 'X', and 'O'. The ' ' character represents an empty square.
6 * Here are the rules of Tic-Tac-Toe:
7 * 
8 * 	Players take turns placing characters into empty squares ' '.
9 * 	The first player always places 'X' characters, while the second player always places 'O' characters.
10 * 	'X' and 'O' characters are always placed into empty squares, never filled ones.
11 * 	The game ends when there are three of the same (non-empty) character filling any row, column, or diagonal.
12 * 	The game also ends if all squares are non-empty.
13 * 	No more moves can be played if the game is over.
14 * 
15 *  
16 * Example 1:
17 * <img alt="" src="https://assets.leetcode.com/uploads/2021/05/15/tictactoe1-grid.jpg" style="width: 253px; height: 253px;" />
18 * Input: board = ["O  ","   ","   "]
19 * Output: false
20 * Explanation: The first player always plays "X".
21 * 
22 * Example 2:
23 * <img alt="" src="https://assets.leetcode.com/uploads/2021/05/15/tictactoe2-grid.jpg" style="width: 253px; height: 253px;" />
24 * Input: board = ["XOX"," X ","   "]
25 * Output: false
26 * Explanation: Players take turns making moves.
27 * 
28 * Example 3:
29 * <img alt="" src="https://assets.leetcode.com/uploads/2021/05/15/tictactoe4-grid.jpg" style="width: 253px; height: 253px;" />
30 * Input: board = ["XOX","O O","XOX"]
31 * Output: true
32 * 
33 *  
34 * Constraints:
35 * 
36 * 	board.length == 3
37 * 	board[i].length == 3
38 * 	board[i][j] is either 'X', 'O', or ' '.
39 * 
40 */
41pub struct Solution {}
42
43// problem: https://leetcode.com/problems/valid-tic-tac-toe-state/
44// discuss: https://leetcode.com/problems/valid-tic-tac-toe-state/discuss/?currentPage=1&orderBy=most_votes&query=
45
46// submission codes start here
47
48impl Solution {
49    pub fn valid_tic_tac_toe(board: Vec<String>) -> bool {
50        false
51    }
52}
53
54// submission codes end
55
56#[cfg(test)]
57mod tests {
58    use super::*;
59
60    #[test]
61    fn test_794() {
62    }
63}
64


Back
© 2025 bowen.ge All Rights Reserved.