Description

Given a collection of candidate numbers and a target number, find all unique combinations in candidates where the candidate numbers sum to target. Each number in candidates may only be used once.

Examples

Input:candidates = [10,1,2,7,6,1,5], target = 8
Output:[[1,1,6],[1,2,5],[1,7],[2,6]]
Explanation:

All unique combinations that sum to 8.

Input:candidates = [4,4,2,1,4,2,2,1,3], target = 6
Output:[[1,1,4],[1,2,3],[2,2,2],[2,4]]
Explanation:

The unique combinations that sum to the target are [[1,1,4],[1,2,3],[2,2,2],[2,4]].

Input:candidates = [3,1,3,5,1,1], target = 4
Output:[[1,3],[1,1,1,1]]
Explanation:

Sorting the candidates reveals enough duplicates to form four unique combinations that sum to the target: [[1,1,4],[1,2,3],[2,2,2],[2,4]].

Constraints

  • 1 ≤ candidates.length ≤ 100
  • 1 ≤ candidates[i] ≤ 50
  • 1 ≤ target ≤ 30

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!