๐ 90. ๅญ้ II
2022ๅนด6ๆ9ๆฅ
- algorithm
๐ 90. ๅญ้ II
้พๅบฆ: ๐
้ฎ้ขๆ่ฟฐ
่งฃๆณ
class Solution {
List<List<Integer>> res = new LinkedList<>();
public List<List<Integer>> subsetsWithDup(int[] nums) {
// ๆ่ทฏ๏ผ
// ้ๅคๆฐ็ป & ๆ ้ๅคๅญ้
int len = nums.length;
Arrays.sort(nums); // ้่ฆๆๅบไฟ่ฏ้กบๅบๆง
LinkedList<Integer> path = new LinkedList<>();
mySol(nums, len, 0, path);
return res;
}
private void mySol(int[] nums, int len, int index, LinkedList<Integer> path) {
// ้ๅฝ็ปๆญขๆกไปถ
if(index > len) {
return;
}
res.add(new LinkedList<>(path));
for(int i = index; i < len; i ++) {
if(i > index && nums[i] == nums[i - 1]) {
continue;
}
path.addLast(nums[i]);
mySol(nums, len, i + 1, path);
path.removeLast();
}
}
}