package leetcode;

/**
 * https://leetcode.com/problems/find-winner-on-a-tic-tac-toe-game/
 */
public class Problem1275 {
    public String tictactoe(int[][] moves) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem1275 prob = new Problem1275();
        System.out.println(prob.tictactoe(new int[][]{
            {0,0},{2,0},{1,1},{2,1},{2,2}
        })); // "A"
        System.out.println(prob.tictactoe(new int[][]{
            {0,0},{1,1},{0,1},{0,2},{1,0},{2,0}
        })); // "B"
        System.out.println(prob.tictactoe(new int[][]{
            {0,0},{1,1},{2,0},{1,0},{1,2},{2,1},{0,1},{0,2},{2,2}
        })); // "Draw"
        System.out.println(prob.tictactoe(new int[][]{
            {0,0},{1,1}
        })); // "Pending"
    }
}

@@ -172,84 +172,97 @@
     
-// TODO%0A        return null
+char%5B%5D%5B%5D board = new char%5B3%5D%5B3%5D;%0A        boolean x = true
 ;%0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D arg
+for (int%5B%5D move : move
 s) %7B
@@ -274,534 +274,1215 @@
     
-Problem1275 prob = new Problem1275();%0A        System.out.println(prob.tictactoe(new int%5B%5D%5B%5D%7B%0A            %7B0,0%7D,%7B2,0%7D,%7B1,1%7D,%7B2,1%7D,%7B2,2%7D%0A        %7D)); // %22A%22%0A        System.out.println(prob.tictactoe(new int%5B%5D%5B%5D%7B%0A            %7B0,0%7D,%7B1,1%7D,%7B0,1%7D,%7B0,2%7D,%7B1,0%7D,%7B2,0%7D%0A        %7D)); // %22B%22%0A        System.out.println(prob.tictactoe(new int%5B%5D%5B%5D%7B%0A            %7B0,0%7D,%7B1,1%7D,%7B2,0%7D,%7B1,0%7D,%7B1,2%7D,%7B2,1%7D,%7B0,1%7D,%7B0,2%7D,%7B2,2%7D%0A        %7D)); // %22Draw%22%0A        System.out.println(prob.tictactoe(new int%5B%5D%5B%5D%7B%0A            %7B0,0%7D,%7B1,1%7D%0A        %7D)); // %22Pending%22
+    board%5Bmove%5B0%5D%5D%5Bmove%5B1%5D%5D = x ? 'X' : 'O';%0A            x = !x;%0A        %7D%0A        if (isWinner(board, 'X')) %7B%0A            return %22A%22;%0A        %7D else if (isWinner(board, 'O')) %7B%0A            return %22B%22;%0A        %7D else if (moves.length == 9) %7B%0A            return %22Draw%22;%0A        %7D%0A        return %22Pending%22;%0A    %7D%0A%0A    private static boolean isWinner(char%5B%5D%5B%5D board, char c) %7B%0A        // horizontal and vertical%0A        for (int i = 0; i %3C 3; i++) %7B%0A            int rowCount = 0;%0A            int colCount = 0;%0A            for (int j = 0; j %3C 3; j++) %7B%0A                if (board%5Bi%5D%5Bj%5D == c) %7B%0A                    colCount++;%0A                %7D%0A                if (board%5Bj%5D%5Bi%5D == c) %7B%0A                    rowCount++;%0A                %7D%0A            %7D%0A            if (rowCount == 3 %7C%7C colCount == 3) %7B%0A                return true;%0A            %7D%0A        %7D%0A        // diagonal%0A        int leftDiagonal = 0;%0A        int rightDiagonal = 0;%0A        for (int i = 0, j = 2; i %3C 3; i++, j--) %7B%0A            if (board%5Bi%5D%5Bi%5D == c) %7B%0A                leftDiagonal++;%0A            %7D%0A            if (board%5Bi%5D%5Bj%5D == c) %7B%0A                rightDiagonal++;%0A            %7D%0A        %7D%0A        return leftDiagonal == 3 %7C%7C rightDiagonal == 3;
 %0A   

Solve problem 1275