Skip to content

Create combination_sum_iv.py #7672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions dynamic_programming/combination_sum_iv.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ def count_of_possible_combinations(target: int) -> int:
return 0
if target == 0:
return 1
count = 0
for i in range(len(array)):
count += count_of_possible_combinations(target - array[i])
return count
return sum([count_of_possible_combinations(target - each) for each in array])

return count_of_possible_combinations(target)

Expand All @@ -63,11 +60,7 @@ def count_of_possible_combinations_with_dp_array(
return 1
if dp_array[target] != -1:
return dp_array[target]
answer = 0
for i in range(len(array)):
answer += count_of_possible_combinations_with_dp_array(
target - array[i], dp_array
)
answer = sum([count_of_possible_combinations_with_dp_array(target - each) for each in array])
dp_array[target] = answer
return answer

Expand Down