Elegant bit manipulation java solution, easy to understand
\nclass Solution {\n\n    private int[] winnings = new int[] { \n            0b000000111, 0b000111000, 0b111000000, \n            0b100100100, 0b010010010, 0b00
```\nclass Solution {\n\n    private int[] winnings = new int[] { \n            0b000000111, 0b000111000, 0b111000000, \n            0b100100100, 0b010010010, 0b001001001, \n            0b100010001, 0b001010100\n    };\n    \n    public boolean validTicTacToe(String[] board) {\n        String s = String.join("", board);\n        int x = toInteger(s, \'X\');\n        int o = toInteger(s, \'O\');\n        boolean xWon = isWon(x);\n        boolean oWon = isWon(o);\n        int xExtraStep = Integer.bitCount(x) - Integer.bitCount(o);\n        if (xWon && oWon) return false;\n        else if (xExtraStep == 0) return !xWon;\n        else if (xExtraStep == 1) return !oWon;\n        else return false;\n    }\n\n    private int toInteger(String s, char k) {\n        int x = 0;\n        for (char c : s.toCharArray()) x = (x << 1) | (c == k ? 1 : 0);\n        return x;\n    }\n\n    private boolean isWon(int x) {\n        for (int w : winnings) {\n            if ((w & x) == w) return true;\n        }\n        return false;\n    }\n}\n```
['Bit Manipulation', 'Java']