This is a recursive backtracking method that finds whether or not a given array can sum to a target amount. This works:
public boolean groupSum(int start, int[] nums, int target) {
if(start >= nums.length)
return target ==0;
if(!groupSum(start+1,nums,target-nums[start]))
return groupSum(start+1,nums,target);
return true;
}
This doesn't:
public boolean groupSum(int start, int[] nums, int target) {
if(start >= nums.length)
return target ==0;
if(!groupSum(start+1,nums,target-nums[start]))
return groupSum(start+1,nums,target);
return false;
}
How does the method even reach the final return statement?