[Java] Clean backtracking code with explanation. Beats 100%
Apply backtracking: Iterate over all ways of choosing 2 numbers and apply all operators on them in both orders (i.e. a operator b and b operator a). Repeat the 
**Apply backtracking:** Iterate over all ways of choosing 2 numbers and apply all operators on them in both orders (i.e. ```a operator b``` and ```b operator a```). Repeat the process recursively on remaining numbers and the result from computation of these 2 numbers. Base case for this recursion is when only one number remains because it represents the final result of the expression. Compare it with 24 and return ```true/false``` accordingly. Return ```true``` as soon as one of the branches returns ```true``` (finds a solution).\n\n- Since we\'re iterating over all ways of choosing 2 numbers, we don\'t need to worry about parentheses because we\'re anyway going through all possible orders of evaluation.\n- Since we\'re applying operators in both orders, we don\'t need to worry about calculating permutations of the input.\n- This approach is good enough for this problem because input size is just 4 otherwise we\'d probably need dynamic programming too.\n-  ```a + b == b + a``` so we don\'t need 2 separate calls for them. Same applies to ```a * b```.\n- Compare doubles using **epsilon** to avoid floating point precision errors like 3.999...999 == 4 returns ```false``` when it should return ```true```.\n- We could create a new array for recursive calls and copy remaining numbers but we could also use the original array itself to make the code faster.\n\n```\n// 0 ms. 100%\nclass Solution {\n    private static final double EPS = 1e-6;\n    private boolean backtrack(double[] A, int n) {\n        if(n == 1) return Math.abs(A[0] - 24) < EPS;\n        for(int i = 0; i < n; i++) {\n            for(int j = i + 1; j < n; j++) {\n                double a = A[i], b = A[j];\n                A[j] = A[n-1];\n                A[i] = a + b;\n                if(backtrack(A, n - 1)) return true;\n                A[i] = a - b;\n                if(backtrack(A, n - 1)) return true;\n                A[i] = b - a;\n                if(backtrack(A, n - 1)) return true;\n                A[i] = a * b;\n                if(backtrack(A, n - 1)) return true;\n                if(Math.abs(b) > EPS) {\n                    A[i] = a / b;\n                    if(backtrack(A, n - 1)) return true;\n                }\n                if(Math.abs(a) > EPS) {\n                    A[i] = b / a;\n                    if(backtrack(A, n - 1)) return true;\n                }\n                A[i] = a; A[j] = b;\n            }\n        }\n        return false;\n    }\n    public boolean judgePoint24(int[] nums) {\n        double[] A = new double[nums.length];\n        for(int i = 0; i < nums.length; i++) A[i] = nums[i];\n        return backtrack(A, A.length);\n    }\n}\n```
['Backtracking', 'Java']