update find_subset_with_target_sum function

pull/306/head
mwiacx 2023-09-27 09:22:45 +08:00
parent 605cc01a03
commit b2134f4dd4
1 changed files with 5 additions and 1 deletions

View File

@ -326,10 +326,14 @@ def find_subset_with_target_sum(nums: List[int], target: int, approximate_thresh
if len(part_idxs) > 0 and (-target * approximate_threshold <= tmpTarget <= target * approximate_threshold):
indexs.append(part_idxs)
elif tmpTarget > sum(nums[start:]) + target * approximate_threshold:
return
elif tmpTarget > 0:
for i in range(start, len(nums)):
num = nums[i]
_inner_helper(start + 1, tmpTarget - num, part_idxs + [i])
if num - target * approximate_threshold > tmpTarget:
continue
_inner_helper(i + 1, tmpTarget - num, part_idxs + [i])
_inner_helper(start=0, tmpTarget=target, part_idxs=[])