class TicTacToe {
    int n;
    int[] rows;
    int[] cols;
    int diag=0;
    int antiDiag = 0;

    public TicTacToe(int n) {
        this.n = n;
        rows = new int[n];
        cols = new int[n];
    }
    
    public int move(int row, int col, int player) {
        int add = 1;
        if(player!=1)
            add = -1;
        rows[row]+=add;
        cols[col]+=add;
        if(row==col)
            diag+=add;
        if(row == n-col-1)
            antiDiag+=add;
        
        if(Math.abs(rows[row])==n||Math.abs(cols[col])==n||Math.abs(diag)==n||Math.abs(antiDiag)==n)
            return player;
        return 0;
    }
}

/**
 * Your TicTacToe object will be instantiated and called as such:
 * TicTacToe obj = new TicTacToe(n);
 * int param_1 = obj.move(row,col,player);
 */

 

posted on 2022-04-14 05:29  阳光明媚的菲越  阅读(19)  评论(0编辑  收藏  举报