Java | XOR to find middle number
Example 1:  More obvious and maintainable code.\n\nclass Solution {\n    public int[] numMovesStones(int a, int b, int c) {\n        int A = Math.min(a, Math.mi
**Example 1:**  More obvious and maintainable code.\n```\nclass Solution {\n    public int[] numMovesStones(int a, int b, int c) {\n        int A = Math.min(a, Math.min(b, c));    // Lowest\n        int C = Math.max(a, Math.max(b, c));    // Highest\n        int B = a ^ b ^ c ^ A ^ C;              // Middle\n        \n        int minMoves = 0;\n        if (C - A >= 4 && (A == B - 2 || C == B + 2))\n            minMoves = 1;                       // A.B.._..C  or  A.._..B.C   (one move of farthest \n                                                //              outer num to between two other nums)\n        else {\n            if (A != B - 1)  minMoves++;        // A.._..B   (else if AB then no moves needed for B)\n            if (C != B + 1)  minMoves++;        // B.._..C   (else if BC then no moves needed for C)\n        }\n        \n        int maxMoves = C - A - 2;               // max is number of positions between highest and lowest \n                                                //      number (C - A - 1) minus a position that is\n                                                //      used by the middle number (-1).\n        return new int[] {minMoves,  maxMoves};\n    }\n}\n```\n**Example 2:** Minimize number of statements.\n```\nclass Solution {\n    public int[] numMovesStones(int a, int b, int c) {\n        int A = Math.min(a, Math.min(b, c));    // Lowest\n        int C = Math.max(a, Math.max(b, c));    // Highest\n        int B = a ^ b ^ c ^ A ^ C;              // Middle\n        return new int[] {((A == B - 1) ? 0 : 1) + ((C == B + 1) ? 0 : 1) + \n                ((C - A >= 4 && (A == B - 2 || C == B + 2)) ? -1 : 0),  C - A - 2};\n    }\n}\n```\n
['Java']