Add +/- 1, check with /n


  • 0

    No need to use abs.

    class TicTacToe {
    public:
        TicTacToe(int n) : n(n), rows(n), cols(n), diag(0), diag2(0) {}
        
        int move(int row, int col, int player) {
            int add = player == 1 ? 1 : -1;
            if ((rows[row] += add) / n ||
                (cols[col] += add) / n ||
                row == col && (diag += add) / n ||
                row + col == n - 1 && (diag2 += add) / n)
                return player;
            return 0;
        }
    
    private:
        int n, diag, diag2;
        vector<int> rows, cols;
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.