C++ solution with comment
\'\'\'\n\n    bool validTicTacToe(vector& board) {\n        int X_size=0, O_size=0;\n        \n        vector> chess (3, vector(3, \' \'));\n        // build th
\'\'\'\n\n    bool validTicTacToe(vector<string>& board) {\n        int X_size=0, O_size=0;\n        \n        vector<vector<char>> chess (3, vector<char>(3, \' \'));\n        // build the chess board; \n        for (int i=0; i<board.size(); ++i) {\n            string cur = board[i];\n            for (int j=0; j<cur.length(); ++j) {\n                if (cur[j] == \'X\') {\n                    chess[i][j] = \'X\';\n                    X_size++;\n                } else if (cur[j] == \'O\') {\n                    chess[i][j] = \'O\';\n                    O_size++;\n                }\n            }\n        }\n        \n        if (X_size < O_size || X_size > O_size + 1) return false;\n        \n        bool X_win = false, O_win = false;\n        // check the row;\n        for (int i=0; i<chess.size(); i++) {\n            if (chess[i][0] != \' \' && chess[i][0]==chess[i][1] && chess[i][0]==chess[i][2]) {\n                if (chess[i][0] == \'X\') {\n                    X_win = true;  \n                } else {\n                    O_win = true;\n                }\n            }\n            \n            if (X_win && O_win) return false;\n        }\n        \n        // check the column\n        for (int j=0; j<chess[0].size(); j++) {\n            if (chess[0][j] != \' \' && chess[0][j]==chess[1][j] && chess[0][j]==chess[2][j]) {\n                if (chess[0][j] == \'X\') {\n                    X_win = true;  \n                } else {\n                    O_win = true;\n                }\n            }\n            if (X_win && O_win) return false;\n        }\n        \n        // check the left diag\n        if (chess[0][0] != \' \' && chess[0][0]==chess[1][1] && chess[0][0]==chess[2][2]) {\n            if (chess[1][1] == \'X\') {\n                X_win = true;  \n            } else {\n                O_win = true;\n            }\n        }\n        \n        // check the right diag\n        if (chess[0][2] != \' \' && chess[0][2]==chess[1][1] && chess[0][2]==chess[2][0]) {\n            if (chess[1][1] == \'X\') {\n                X_win = true;  \n            } else {\n                O_win = true;\n            }\n        }\n        \n        if (X_size == O_size && X_win) return false;\n        if (X_size == O_size+1 && O_win) return false;\n        \n        return true;\n    }\n\n\'\'\'
[]