class Solution {
Map<Integer, Integer> results = new HashMap<>();
public int combinationSum4(int[] nums, int target) {
if (results.keySet().contains(target)) {
return results.get(target);
}
if (target < 0) {
return 0;
}
int n = nums.length;
int res = 0;
for (int i = 0; i < n; i++) {
boolean valid = true;
if (target - nums[i] == 0) {
res++;
} else {
res += combinationSum4(nums, target - nums[i]);
}
}
results.put(target, res);
return res;
}
}