JAVA- Easy to understand 0ms 100% solution
\nclass Solution {\n    public boolean validTicTacToe(String[] board) {\n        char[][] c= new char[3][3];\n        int x = 0;\n        int o = 0;\n        bo
```\nclass Solution {\n    public boolean validTicTacToe(String[] board) {\n        char[][] c= new char[3][3];\n        int x = 0;\n        int o = 0;\n        boolean xwin = false;\n        boolean owin = false;\n        for(int i = 0;i<3;i++){\n            for(int j= 0;j<3;j++){\n                c[i][j]= board[i].charAt(j);\n                if(c[i][j]==\'X\')\n                    x++;\n                if(c[i][j]==\'O\')\n                    o++;\n            }\n        }\n        \n        //row check\n        for(int i = 0;i<3;i++){\n            if(c[i][0]==c[i][1]&& c[i][1]==c[i][2]){\n                if(c[i][0]==\'X\')\n                    xwin = true;\n                if(c[i][0]==\'O\')\n                    owin = true;\n            }\n        }\n        \n        //column check\n        for(int i = 0;i<3;i++){\n            if(c[0][i]==c[1][i] && c[1][i]==c[2][i]){\n                if(c[0][i]==\'X\')\n                    xwin = true;\n                if(c[0][i]==\'O\')\n                    owin = true;\n            }\n        }\n        \n        //left diagonal check\n        if(c[0][0]==c[1][1] && c[1][1]==c[2][2]){\n            if(c[0][0]==\'X\')\n                xwin = true;\n            if(c[0][0]==\'O\')\n                owin = true;\n        }\n        \n        //right diagonal check\n        if(c[0][2]==c[1][1] && c[1][1]==c[2][0]){\n            if(c[0][2]==\'X\')\n                xwin = true;\n            if(c[0][2]==\'O\')\n                owin = true;\n        }\n        \n        if(xwin){\n            if(x-o==1)\n                return true;\n            return false;\n        }\n        if(owin){\n            if(x-o==0)\n                return true;\n            return false;\n        }\n        if(x==o || x-o==1)\n            return true;\n        return false;\n    }\n}\n```
[]