|
1 | 1 | package com.fishercoder.solutions;
|
2 | 2 |
|
3 |
| -/** |
4 |
| - * 1275. Find Winner on a Tic Tac Toe Game |
5 |
| - * |
6 |
| - * Tic-tac-toe is played by two players A and B on a 3 x 3 grid. |
7 |
| - * |
8 |
| - * Here are the rules of Tic-Tac-Toe: |
9 |
| - * Players take turns placing characters into empty squares (" "). |
10 |
| - * The first player A always places "X" characters, while the second player B always places "O" characters. |
11 |
| - * "X" and "O" characters are always placed into empty squares, never on filled ones. |
12 |
| - * The game ends when there are 3 of the same (non-empty) character filling any row, column, or diagonal. |
13 |
| - * The game also ends if all squares are non-empty. |
14 |
| - * No more moves can be played if the game is over. |
15 |
| - * Given an array moves where each element is another array of size 2 corresponding to the row and column of |
16 |
| - * the grid where they mark their respective character in the order in which A and B play. |
17 |
| - * |
18 |
| - * Return the winner of the game if it exists (A or B), in case the game ends in a draw return "Draw", |
19 |
| - * if there are still movements to play return "Pending". |
20 |
| - * |
21 |
| - * You can assume that moves is valid (It follows the rules of Tic-Tac-Toe), the grid is initially empty and A will play first. |
22 |
| - * |
23 |
| - * Example 1: |
24 |
| - * Input: moves = [[0,0],[2,0],[1,1],[2,1],[2,2]] |
25 |
| - * Output: "A" |
26 |
| - * Explanation: "A" wins, he always plays first. |
27 |
| - * "X " "X " "X " "X " "X " |
28 |
| - * " " -> " " -> " X " -> " X " -> " X " |
29 |
| - * " " "O " "O " "OO " "OOX" |
30 |
| - * |
31 |
| - * Example 2: |
32 |
| - * Input: moves = [[0,0],[1,1],[0,1],[0,2],[1,0],[2,0]] |
33 |
| - * Output: "B" |
34 |
| - * Explanation: "B" wins. |
35 |
| - * "X " "X " "XX " "XXO" "XXO" "XXO" |
36 |
| - * " " -> " O " -> " O " -> " O " -> "XO " -> "XO " |
37 |
| - * " " " " " " " " " " "O " |
38 |
| - * |
39 |
| - * Example 3: |
40 |
| - * Input: moves = [[0,0],[1,1],[2,0],[1,0],[1,2],[2,1],[0,1],[0,2],[2,2]] |
41 |
| - * Output: "Draw" |
42 |
| - * Explanation: The game ends in a draw since there are no moves to make. |
43 |
| - * "XXO" |
44 |
| - * "OOX" |
45 |
| - * "XOX" |
46 |
| - * |
47 |
| - * Example 4: |
48 |
| - * Input: moves = [[0,0],[1,1]] |
49 |
| - * Output: "Pending" |
50 |
| - * Explanation: The game has not finished yet. |
51 |
| - * "X " |
52 |
| - * " O " |
53 |
| - * " " |
54 |
| - * |
55 |
| - * Constraints: |
56 |
| - * 1 <= moves.length <= 9 |
57 |
| - * moves[i].length == 2 |
58 |
| - * 0 <= moves[i][j] <= 2 |
59 |
| - * There are no repeated elements on moves. |
60 |
| - * moves follow the rules of tic tac toe. |
61 |
| - * */ |
62 | 3 | public class _1275 {
|
63 | 4 | public static class Solution1 {
|
64 | 5 | public String tictactoe(int[][] moves) {
|
|
0 commit comments