Subsets II

Medium

Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set).

Note:The solution set must not contain duplicate subsets.

Example:

Input:
 [1,2,2]

Output:

[
  [2],
  [1],
  [1,2,2],
  [2,2],
  [1,2],
  []
]

Analysis

这道题应该算Subsets的follow-up,解决input中有重复元素的情况。

不过对策也很直观,就是当遇到重复元素时,跳过相应的backtracking即可。

Solution

Backtracking

Iterative

Last updated

Was this helpful?