import java.util.*;
public class Solution {
public boolean ans = false;
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
* @param nums int整型ArrayList
* @return bool布尔型
*/
public boolean Point24(ArrayList<Integer> nums) {
// write code here
process(0.0, nums);
return ans;
}
public void process(double previousTotal, ArrayList<Integer> remainNums) {
if (0 == remainNums.size()) {
if (previousTotal == (double) 24) {
ans = true;
}
return;
}
for (int currentNumber : remainNums) {
ArrayList<Integer> copyArr = new ArrayList<>(remainNums);
copyArr.remove(Integer.valueOf(currentNumber));
process(previousTotal + currentNumber, copyArr);
process(previousTotal - currentNumber, copyArr);
process(previousTotal * currentNumber, copyArr);
process(previousTotal / currentNumber, copyArr);
}
}
}