一:题目
二:上码
class Solution {
/**
- 先排序
- 树层去重:那么直接在从横向循环中去重即可
*/
List<List<Integer>> ans = new ArrayList<>();
List<Integer> path = new ArrayList<>();
public void getAns(int[] nums,int st) {
ans.add(new ArrayList<>(path));
for (int i = st; i < nums.length; i++) {
if (i-1 >= st && nums[i] == nums[i-1]) continue;
path.add(nums[i]);
getAns(nums,i+1);
path.remove(path.size()-1);
}
}
public List<List<Integer>> subsetsWithDup(int[] nums) {
Arrays.sort(nums);
getAns(nums,0);
return ans;
}
}