---
# System prepended metadata

title: 0348. Design Tic-Tac-Toe
tags: [Leetcode, Medium, Microsoft]

---

# 0348. Design Tic-Tac-Toe
###### tags: `Leetcode` `Microsoft` `Medium`
Link: https://leetcode.com/problems/design-tic-tac-toe/

## 思路 O(1) O(N)
和 1275 一样的思路
## Code
```java=
class TicTacToe {
    int size;
    int[] rows, cols;
    int diagonal, antiDiagonal;
    public TicTacToe(int n) {
        this.size = n;
        rows = new int[n];
        cols = new int[n];
        diagonal = 0;
        antiDiagonal = 0;
    }
    
    public int move(int row, int col, int player) {
        player = player==1?1:-1;
        rows[row]+=player;
        cols[col]+=player;
        diagonal += row==col? player:0;
        antiDiagonal += row+col==size-1? player:0;
        
        if(Math.abs(rows[row])==size||Math.abs(cols[col])==size||Math.abs(diagonal)==size||Math.abs(antiDiagonal)==size){
            return player==1?1:2;
        }
        return 0;
    }
}

```