Recca Chao 的 gitHub page

推廣網站開發,包含 Laravel 和 Kotlin 後端撰寫、自動化測試、讀書心得等。Taiwan Kotlin User Group 管理員。

View on GitHub

Hi, here’s your problem today. This problem was recently asked by Twitter:

Given a list of numbers and a target number, find all possible unique subsets of the list of numbers that sum up to the target number. The numbers will all be positive numbers.

Here’s an example and some starter code.

def sum_combinations(nums, target):

Fill this in.

print(sum_combinations([10, 1, 2, 7, 6, 1, 5], 8))

[(2, 6), (1, 1, 6), (1, 2, 5), (1, 7)]