1275. Find Winner on a Tic Tac Toe Game Easy
1/**
2 * [1275] Find Winner on a Tic Tac Toe Game
3 *
4 * Tic-tac-toe is played by two players A and B on a 3 x 3 grid. The rules of Tic-Tac-Toe are:
5 *
6 * Players take turns placing characters into empty squares ' '.
7 * The first player A always places 'X' characters, while the second player B always places 'O' characters.
8 * 'X' and 'O' characters are always placed into empty squares, never on filled ones.
9 * The game ends when there are three of the same (non-empty) character filling any row, column, or diagonal.
10 * The game also ends if all squares are non-empty.
11 * No more moves can be played if the game is over.
12 *
13 * Given a 2D integer array moves where moves[i] = [rowi, coli] indicates that the i^th move will be played on grid[rowi][coli]. return the winner of the game if it exists (A or B). In case the game ends in a draw return "Draw". If there are still movements to play return "Pending".
14 * You can assume that moves is valid (i.e., it follows the rules of Tic-Tac-Toe), the grid is initially empty, and A will play first.
15 *
16 * Example 1:
17 * <img alt="" src="https://assets.leetcode.com/uploads/2021/09/22/xo1-grid.jpg" style="width: 244px; height: 245px;" />
18 * Input: moves = [[0,0],[2,0],[1,1],[2,1],[2,2]]
19 * Output: "A"
20 * Explanation: A wins, they always play first.
21 *
22 * Example 2:
23 * <img alt="" src="https://assets.leetcode.com/uploads/2021/09/22/xo2-grid.jpg" style="width: 244px; height: 245px;" />
24 * Input: moves = [[0,0],[1,1],[0,1],[0,2],[1,0],[2,0]]
25 * Output: "B"
26 * Explanation: B wins.
27 *
28 * Example 3:
29 * <img alt="" src="https://assets.leetcode.com/uploads/2021/09/22/xo3-grid.jpg" style="width: 244px; height: 245px;" />
30 * Input: moves = [[0,0],[1,1],[2,0],[1,0],[1,2],[2,1],[0,1],[0,2],[2,2]]
31 * Output: "Draw"
32 * Explanation: The game ends in a draw since there are no moves to make.
33 *
34 *
35 * Constraints:
36 *
37 * 1 <= moves.length <= 9
38 * moves[i].length == 2
39 * 0 <= rowi, coli <= 2
40 * There are no repeated elements on moves.
41 * moves follow the rules of tic tac toe.
42 *
43 */
44pub struct Solution {}
45
46// problem: https://leetcode.com/problems/find-winner-on-a-tic-tac-toe-game/
47// discuss: https://leetcode.com/problems/find-winner-on-a-tic-tac-toe-game/discuss/?currentPage=1&orderBy=most_votes&query=
48
49// submission codes start here
50
51impl Solution {
52 pub fn tictactoe(moves: Vec<Vec<i32>>) -> String {
53 String::new()
54 }
55}
56
57// submission codes end
58
59#[cfg(test)]
60mod tests {
61 use super::*;
62
63 #[test]
64 fn test_1275() {
65 }
66}
67
Back
© 2025 bowen.ge All Rights Reserved.