@@ -0,0 +1,1667 @@
+// Solution that is based on backtracking and possible time complexity is either exponential or%0A// even factorial, but it does not really matter here, because of the problem constaints -%0A// there are 495 solutions in total (404 solvable, 91 not solvable).%0A//%0A// Solution beats 89.58%25 of submissions.%0A//%0A// Idea:%0A// Initially we have 4 numbers, at each recursive call we take the number from array and build%0A// tmp array of (len - 1) elements left. Then we try all operators (*, +, -, /) on every number in%0A// tmp array with number we extracted, and replace with the result in tmp array for that position.%0A// We keep doing it until array has only one element, at this point it is either 24 (within%0A// threshold) or not.%0Aclass Solution %7B%0A  public boolean judgePoint24(int%5B%5D nums) %7B%0A    double%5B%5D tmp = new double%5Bnums.length%5D;%0A    for (int i = 0; i %3C nums.length; i++) tmp%5Bi%5D = nums%5Bi%5D;%0A    return solve(tmp);%0A  %7D%0A%0A  public boolean solve(double%5B%5D nums) %7B%0A    if (nums.length == 1) return Math.abs(nums%5B0%5D - 24) %3C= 1e-3;%0A    for (int i = 0; i %3C nums.length; i++) %7B%0A      double%5B%5D tmp = new double%5Bnums.length - 1%5D;%0A      int p = 0;%0A      for (int j = 0; j %3C i; j++) tmp%5Bp++%5D = nums%5Bj%5D;%0A      for (int j = i+1; j %3C nums.length; j++) tmp%5Bp++%5D = nums%5Bj%5D;%0A%0A      double a = nums%5Bi%5D;%0A      for (int k = 0; k %3C tmp.length; k++) %7B%0A        double orig = tmp%5Bk%5D;%0A        tmp%5Bk%5D = orig + a;%0A        if (solve(tmp)) return true;%0A        tmp%5Bk%5D = orig - a;%0A        if (solve(tmp)) return true;%0A        tmp%5Bk%5D = orig / a;%0A        if (solve(tmp)) return true;%0A        tmp%5Bk%5D = orig * a;%0A        if (solve(tmp)) return true;%0A        tmp%5Bk%5D = orig;%0A      %7D%0A    %7D%0A    return false;%0A  %7D%0A%7D%0A

add solution