Two ways to make 5
Input
nums = [2,3,5], target = 5
Output
[[2, 3], [5]]
Subsets [2,3] and [5] sum to 5. Returned list sorted lexicographically.
Full lesson preview
Find all unique subsets of a list of non-negative integers that sum to a target. Each number may be used at most once.
Problem statement
Task
Examples
Input
nums = [2,3,5], target = 5
Output
[[2, 3], [5]]
Subsets [2,3] and [5] sum to 5. Returned list sorted lexicographically.
Input format
Output format
Constraints
Samples
Input
nums = [2,4,6,3], target = 6
Output
[[2, 4], [6]]
Two subsets sum to 6: [2,4] and [6].