Long but modularized, easy to understand C++ Solution, 0ms, beats 100%
Runtime: 0 ms, faster than 100.00% of C++ online submissions for Valid Tic-Tac-Toe State.\nMemory Usage: 8.3 MB, less than 40.00% of C++ online submissions for 
Runtime: 0 ms, faster than 100.00% of C++ online submissions for Valid Tic-Tac-Toe State.\nMemory Usage: 8.3 MB, less than 40.00% of C++ online submissions for Valid Tic-Tac-Toe State.\n\n```\nclass Solution {\npublic:\n    bool validTicTacToe(vector<string>& board) {\n        \n        int noOs = 0;\n        int noXs = 0;\n        \n        bool flagX = false;\n        bool flagO = false;\n        \n        for(int i=0; i<board.size(); i++)\n        {\n            if(checkRow(board[i]))\n            {\n                if(board[i][0] == \'X\')\n                {\n                    if(flagO) return false;\n                    flagX = true;\n                }\n                \n                if(board[i][0] == \'O\')\n                {\n                    if(flagX) return false;\n                    flagO = true;\n                }\n            }\n            \n            if(checkCol(board,i))\n            {\n                if(board[0][i] == \'X\')\n                {\n                    if(flagO) return false;\n                    flagX = true;\n                }\n                \n                if(board[0][i] == \'O\')\n                {\n                    if(flagX) return false;\n                    flagO = true;\n                }\n            }\n            \n            for(char ch : board[i])\n            {\n                if(ch == \'O\')\n                    noOs++;\n                else if(ch == \'X\')\n                    noXs++;\n            }\n        }\n        \n        if(checkDiagPrim(board))\n        {\n            if(board[0][0] == \'X\')\n            {\n                if(flagO) return false;\n                flagX = true;\n            }\n                \n            if(board[0][0] == \'O\')\n            {\n                if(flagX) return false;\n                flagO = true;\n            }\n        }\n        \n        if(checkDiagSec(board))\n        {\n            if(board[0][2] == \'X\')\n            {\n                if(flagO) return false;\n                flagX = true;\n            }\n                \n            if(board[0][2] == \'O\')\n            {\n                if(flagX) return false;\n                flagO = true;\n            }\n        }\n        \n        if(noOs > noXs || (noXs-noOs > 1))\n            return false;\n        if(flagX && (noXs <= noOs))\n            return false;\n        if(flagO && (noXs != noOs))\n            return false;\n        \n        if(flagX && flagO)\n            return false;\n        \n        return true;\n    }\n    \n    bool checkRow(string s)\n    {\n        char check = s[0];\n        for(char ch : s)\n            if(ch == \' \' || ch != check)\n                return false;\n        return true;\n    }\n    \n    bool checkCol(vector<string>& board, int i)\n    {\n        int r = board.size();\n        char check = board[0][i];\n        \n        for(int j=0; j<r; j++)\n            if(board[j][i] == \' \' || board[j][i] != check)\n                return false;\n        return true;\n    }\n    \n    bool checkDiagPrim(vector<string>& board)\n    {\n        char check = board[0][0];\n        int r = board.size();\n        \n        for(int i=0; i<r; i++)\n            if(board[i][i] == \' \' || board[i][i] != check)\n                return false;\n        return true;\n    }\n    \n    bool checkDiagSec(vector<string>& board)\n    {\n        char check = board[0][2];\n        int r = board.size()-1;\n        for(int i=0; i<=r; i++)\n            if(board[i][r-i] == \' \' || board[i][r-i] != check)\n                return false;\n        \n        return true;\n    }\n};\n
['C++']