| C++ Solution | Simple H Bhai |
Count the number of Xs and Os\n1. Ensure there is at most one winner\n1. Ensure a valid count of Xs and Os for each winner\n1. Ensure a valid count of Xs and Os
1. Count the number of Xs and Os\n1. Ensure there is at most one winner\n1. Ensure a valid count of Xs and Os for each winner\n1. Ensure a valid count of Xs and Os if there is no winner\n```\nint countChar(vector<string> board, char c) {\n    int count = 0;\n    for(int i=0; i<board.size(); i++) \n        for(auto &chr : board[i]) \n            if(chr == c) count++;\n    return count;\n}\n\nbool winGame(vector<string> board, char c) {\n    for(int i=0; i<3; i++) if(board[i][0]==c && board[i][1]==c && board[i][2] ==c) return true;\n    for(int i=0; i<3; i++) if(board[0][i]==c && board[1][i]==c && board[2][i] ==c) return true;\n    return (board[0][0]==c && board[1][1]==c && board[2][2]==c) || (board[0][2]==c && board[1][1]==c && board[2][0]==c);\n}\nclass Solution {\npublic:\n    bool validTicTacToe(vector<string>& board) {\n        int countX,countO;\n        bool winX, winO;\n        countX = countChar(board,\'X\');\n        countO = countChar(board,\'O\');\n        winX = winGame(board,\'X\');\n        winO = winGame(board,\'O\');\n        if(winX && winO) return false;\n        if(winX) return countX == countO+1;\n        if(winO) return countX == countO;\n        return countX==countO+1 || countX==countO;\n    }\n};\n```
[]