---
# System prepended metadata

title: 0090. Subsets II
tags: [Leetcode, DFS, Medium, Backtracking]

---

#  0090. Subsets II
###### tags: `Leetcode` `Medium` `Backtracking` `DFS`
Link: https://leetcode.com/problems/subsets-ii/
## 思路
和[0040. Combination Sum II](https://hackmd.io/cOOug_AXSUeBnJKIjdF2IA)有点像 都是要找不重复的子集
典型backtracking问题
## Code
```java=
class Solution {
    public List<List<Integer>> subsetsWithDup(int[] nums) {
        Arrays.sort(nums);
        List<List<Integer>> ans = new ArrayList<>();
        dfs(ans, nums, new ArrayList<>(), 0);
        return ans;
    }
    private void dfs(List<List<Integer>> ans, int[] nums, List<Integer> curr, int start){
        ans.add(new ArrayList<>(curr));
        for(int i=start; i<nums.length; i++){
            if(i>start && nums[i]==nums[i-1]) continue;
            curr.add(nums[i]);
            dfs(ans, nums, curr, i+1);
            curr.remove(curr.size()-1);
        }
    }
}
```
