P20056 [GeeksforGeeks] Combination sum ii
普及
题目描述

You are given a collection of numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sum to the target. Each number in candidates may only be used once in the combination.
Note: The solution set must not contain duplicate combinations.
Example:
Input: candidates = [10,1,2,7,6,1,5], target = 8.
Output: [[1,1,6], [1,2,5], [1,7], [2,6]].
Explanation: These are the unique combinations whose sum is equal to the target.
Your Task:
Complete the function vector> combinationSum2(), which takes a vector "candidates" and an integer target and returns a vector of vector consisting of all unique combinations whose sum is equal to the target.
Expected Time Complexity: O(2^{nk}).
Expected Auxiliary Space: O(k
x).
Constraints:
1 <= candidates.length <= 100.
1 <= candidates[i] <= 50.
1 <= target <= 30.

输入格式

见题面

输出格式

见题面

样例输入
candidates = [10,1,2,7,6,1,5], target = 8.
样例输出
[[1,1,6], [1,2,5], [1,7], [2,6]].