Best Java Solution || Beats 100%
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public boolean validTicTacToe(String[] board) {\n        int[] arr=new int[2];\n        boolean xwin=false,owin=false;\n        int xdiag=0,odiag=0;\n        for(int i=0;i<3;i++){\n            int x=0,o=0;\n            for(int j=0;j<3;j++)\n            {\n                if(i==0){\n                    if(board[i].charAt(j)==\'X\' && board[i+1].charAt(j)==\'X\' && board[i+2].charAt(j)==\'X\')xwin=true;\n                    if(board[i].charAt(j)==\'O\' && board[i+1].charAt(j)==\'O\' && board[i+2].charAt(j)==\'O\')owin=true;\n                }\n                if(board[i].charAt(j)==\'X\'){\n                    if(i==j)xdiag++;\n                    arr[1]++;\n                    x++;\n                }\n                else if(board[i].charAt(j)==\'O\'){\n                    if(i==j)odiag++;\n                    arr[0]++;\n                    o++;\n                }\n            }\n            if(o==3 && owin)return false;\n            if(owin && xwin)return false;\n            if(x==3)xwin=true;\n            else if(o==3)owin=true;\n        }\n\n        if(xdiag==3)xwin=true;\n        if(odiag==3)owin=true;\n\n        if(board[0].charAt(2)==\'X\' && board[1].charAt(1)==\'X\' && board[2].charAt(0)==\'X\')xwin=true;\n        if(board[0].charAt(2)==\'O\' && board[1].charAt(1)==\'O\' && board[2].charAt(0)==\'O\')owin=true;\n\n        if(arr[0]>=arr[1] && xwin || (arr[1]>arr[0] && owin))return false;\n        if(arr[0]>arr[1] || Math.abs(arr[0]-arr[1])>1)return false;\n        \n        if(xwin&&owin) return false;\n        else return true;\n    }\n}\n```
['Java']