Easy Java 1ms Solution with comments
\nclass Solution {\n    public boolean validTicTacToe(String[] board) {\n            int numX = 0;\n            int numO = 0;\n            boolean xWins =false;
```\nclass Solution {\n    public boolean validTicTacToe(String[] board) {\n            int numX = 0;\n            int numO = 0;\n            boolean xWins =false;\n            boolean oWins = false;\n            for (int i= 0; i< 3; i++){\n                for(char c: board[i].toCharArray()) {\n                if(c == \'X\') numX++;\n                else if(c== \'O\')numO++;\n            }\n            // check horizontal at row i\n            if(board[i].equals("XXX"))xWins = true;\n            else if(board[i].equals("OOO"))oWins = true;\n            // check vertical at column i\n            String vertical = new StringBuilder()\n                .append(board[0].charAt(i))\n                .append(board[1].charAt(i))\n                .append(board[2].charAt(i))\n                .toString();\n            if(vertical.equals("XXX"))xWins = true;\n            else if(vertical.equals("OOO")) oWins = true;\n            }\n        // left diagonal\n            String diag1= new StringBuilder() // as the matrix will always be of 3x3 so we do not need to use i in checking diagonal we can just direct use the indices 0,1,2\n                .append(board[0].charAt(0))\n                .append(board[1].charAt(1))\n                .append(board[2].charAt(2))\n                .toString();\n            if(diag1.equals("XXX")) xWins = true;\n            else if(diag1.equals("OOO")) oWins = true;\n        // right diagonal\n            String diag2 = new StringBuilder() \n                .append(board[0].charAt(2))\n                .append(board[1].charAt(1))\n                .append(board[2].charAt(0))\n                .toString();\n            if(diag2.equals("XXX")) xWins =true;\n            else if(diag2.equals("OOO")) oWins= true;\n            if(xWins) {\n                return !oWins && numX - numO == 1;\n            }else if(oWins){\n                return numX == numO;\n            }\n        return numX>=numO && numX-numO<=1; // if none of them wins then we will check the number of x should be atleast equal to number of o and number of x should be atmost 1 more than the number of o \n    }\n}\n```
['String', 'Java']