Дан массив различных положительных целых чисел candidates и целевое число target. Найдите все уникальные комбинации из candidates, где сумма равна target.
Один и тот же элемент можно использовать неограниченное число раз. Комбинации отсортированы лексикографически.
def combination_sum(candidates: list[int], target: int) -> list[list[int]]:
combination_sum([2, 3, 6, 7], 7) → [[2, 2, 3], [7]]
combination_sum([2, 3, 5], 8) → [[2, 2, 2, 2], [2, 3, 3], [3, 5]]
combination_sum([2], 1) → []
- 1 ≤ len(candidates) ≤ 30
- 2 ≤ candidates[i] ≤ 40
- 1 ≤ target ≤ 40
- Все candidates различны
candidates = [2,3,6,7]target = 7[[2,2,3],[7]]candidates = [2,3,5]target = 8[[2,2,2,2],[2,3,3],[3,5]]candidates = [2]target = 1[]