Solved LeetCode program · 40 of 1,000
#0040 · Combination Sum II
Original English source
Keep a shared nums holding 10, 1, 2, 7, 6, 1, and 5. Sort nums. Keep a shared target of 8. Keep a shared parts as an empty list of text. Keep a shared answers as an empty list of text.
To combine from index (a whole number) with total (a whole number). If total is target, The built is join parts with ",", Place built into answers, then return. If total is more than target, return. If index is at least 7, return.
For every position from index to 6.
If position is more than index and item position of nums is item (position minus 1) of nums, skip to the next one. The value is item position of nums.
If total plus value is at most target.
The piece is format whole number value as text. Place piece into parts. Combine from position plus 1 with total plus value. Remove the last item from parts.
Combine from 0 with 0. For each answer in answers, display answer.
Expected stdout
1,1,6 1,2,5 1,7 2,6