Solution
C++ []\nclass Solution {\npublic:\n    bool validTicTacToe(vector<string>& board) \n    {\n        int turn = 0, diag = 0, adg = 0, i, j;\n        bool xwin = f
```C++ []\nclass Solution {\npublic:\n    bool validTicTacToe(vector<string>& board) \n    {\n        int turn = 0, diag = 0, adg = 0, i, j;\n        bool xwin = false, owin = false;\n        vector<int> row(3), col(3);\n        for(i = 0; i < 3; i ++)\n        {\n            for(j = 0; j < 3; j ++)\n            {\n                if(\'X\' == board[i][j])\n                {\n                    turn ++;\n                    row[i] ++;\n                    col[j] ++;\n                    \n                    if(i == j)\n                    {\n                        diag ++;\n                    }\n                    if(i + j == 2)\n                    {\n                        adg ++;\n                    }\n                }\n                else if(\'O\' == board[i][j])\n                {\n                    turn --;\n                    row[i] --;\n                    col[j] --;\n                    \n                    if(i == j)\n                    {\n                        diag --;\n                    }\n                    if(i + j == 2)\n                    {\n                        adg --;\n                    }\n                }\n            }\n        }\n        for(i = 0; i < 3; i ++)\n        {\n            if(3 == row[i] || 3 == col[i])\n            {\n                xwin = true;\n            }\n            if(-3 == row[i] || -3 == col[i])\n            {\n                owin = true;\n            }\n        }\n        if(3 == diag || 3 == adg)\n        {\n            xwin = true;\n        }\n        if(-3 == diag || -3 == adg)\n        {\n            owin = true;\n        }\n        if(xwin && owin)\n        {\n            return false;\n        }\n        if(turn != 0 && turn != 1)\n        {\n            return false;\n        }\n        if((xwin && turn != 1) || (owin && turn != 0))\n        {\n            return false;\n        }\n        return true;\n    }\n};\n```\n\n```Python3 []\nclass Solution:\n    def validTicTacToe(self, board: List[str]) -> bool:\n        rows, cols, diag1, diag2 = [0]*3, [0]*3, 0, 0 \n        o, x = 0, 0\n        for i in range(len(board)):\n            for j in range(len(board[0])):\n                if board[i][j] == "O":\n                    o+=1\n                    rows[i]+=1\n                    cols[j]+=1\n                    if i == j:\n                        diag1+=1\n                    if i+j == 2:\n                        diag2+=1\n                if board[i][j] == "X":\n                    x+=1\n                    rows[i]-=1\n                    cols[j]-=1\n                    if i == j:\n                        diag1-=1\n                    if i+j == 2:\n                        diag2-=1\n        \n        player1 = 3 in rows or 3 in cols or diag1 == 3 or diag2 == 3\n        player2 = -3 in rows or -3 in cols or diag1 == -3 or diag2 == -3\n        \n        if o != x and x-o != 1: return False\n        if player1 and player2: return False\n        if player1: return o == x\n        if player2: return x-o == 1\n\n        return True\n```\n\n```Java []\nclass Solution {\n    public boolean validTicTacToe(String[] board) {\n        if (board == null || board.length == 0) {\n            return false;\n        }\n\n        int n = board.length;\n        int diag1 = 0;\n        int diag2 = 0;\n        int turnsDiff = 0;\n        boolean xWin = false;\n        boolean oWin = false;\n        char c;\n\n        for (int i = 0; i < n; i++) {\n            int row = 0;\n            int col = 0;\n            for (int j = 0; j < n; j++) {\n                c = board[i].charAt(j);\n                if (c == \'X\') {\n                    row++;\n                    turnsDiff++;\n                } else if (c == \'O\') {\n                    row--;\n                    turnsDiff--;\n                }\n                c = board[j].charAt(i);\n                if (c == \'X\') {\n                    col++;\n                } else if (c == \'O\') {\n                    col--;\n                }\n            }\n            c = board[i].charAt(i);\n            if (c == \'X\') {\n                diag1++;\n            } else if (c == \'O\') {\n                diag1--;\n            }\n            c = board[i].charAt(n - 1 - i);\n            if (c == \'X\') {\n                diag2++;\n            } else if (c == \'O\') {\n                diag2--;\n            }\n            if (row == n || col == n || diag1 == n || diag2 == n) {\n                if (oWin) {\n                    return false;\n                }\n                xWin = true;\n            }\n            if (row == -n || col == -n || diag1 == -n || diag2 == -n) {\n                if (xWin) {\n                    return false;\n                }\n                oWin = true;\n            }\n        }\n        if (turnsDiff < 0 || turnsDiff > 1) {\n            return false;\n        }\n        if ((turnsDiff == 0 && xWin) || (turnsDiff == 1 && oWin)) {\n            return false;\n        }\n        return true;\n    }\n}\n```\n
['C++', 'Java', 'Python3']