class Solution { public boolean judgePoint24(int[] nums) { double[] a = new double[]{nums[0],nums[1],nums[2],nums[3]}; return find(a); } public boolean find(double[] a) { if(a.length == 1) return Math.abs(a[0] - 24) < 0.01; for(int i = 0; i < a.length; i++) { for(int j = i + 1; j < a.length; j++) { double[] b = new double[a.length-1]; for(int k = 0, index = 0; k < a.length; k++) { if(k != i && k != j) { b[index++] = a[k]; } } for(double d : compute(a[i],a[j])) { b[b.length-1] = d; if(find(b)) return true; } } } return false; } public double[] compute(double a, double b) { return new double[]{a+b,a*b,a-b,b-a,a/b,b/a}; } }