当前位置:网站首页>Leetcode 90: subset II
Leetcode 90: subset II
2022-07-07 07:53:00 【Swarford】
link
subject :
Ideas : to flash back ( Elements can be duplicated and cannot be checked )
And A subset of The difference is that the elements given by the title are repeated , If you follow the previous practice, the answer will be repeated :


Here, you need to add conditions for selection to trim nodes !
① If there are repeating elements, you have to Sort !, Let the same element lean against ⼀ rise ,
② If you find that nums[i] == nums[i-1] be skip ! meanwhile i>start
Java Realization :
class Solution {
List<List<Integer>> res=new LinkedList<>();
LinkedList<Integer> path=new LinkedList<>();
public List<List<Integer>> subsetsWithDup(int[] nums) {
Arrays.sort(nums);
dfs(nums,0);
return res;
}
void dfs(int[] nums,int start){
res.add(new LinkedList(path));
for(int i=start;i<nums.length;i++){
// To make a choice
// trim , Adjacent nodes with the same value are traversed only once
if(i>start && nums[i]==nums[i-1]){
// i>start !
continue;
}
path.add(nums[i]);
dfs(nums,i+1);
// revoke
path.removeLast();
}
}
}
Be careful :i >start !
边栏推荐
- After the interview, the interviewer roast in the circle of friends
- @component(““)
- 测试周期被压缩?教你9个方法去应对
- Use and analysis of dot function in numpy
- Ansible
- Tongda injection 0day
- Hands on deep learning (IV) -- convolutional neural network CNN
- Live online system source code, using valueanimator to achieve view zoom in and out animation effect
- LeetCode 40:组合总和 II
- 【webrtc】m98 screen和window采集
猜你喜欢
随机推荐
Common method signatures and meanings of Iterable, collection and list
微信小程序中的路由跳转
LeetCode 90:子集 II
Hands on deep learning (IV) -- convolutional neural network CNN
【obs】win-capture需要winrt
nacos
leetcode:105. Constructing binary trees from preorder and inorder traversal sequences
Is the test cycle compressed? Teach you 9 ways to deal with it
Gslx680 touch screen driver source code analysis (gslx680. C)
Linux server development, MySQL process control statement
[2022 ACTF]web题目复现
Resource create package method
直播平台源码,可折叠式菜单栏
[performance pressure test] how to do a good job of performance pressure test?
测试周期被压缩?教你9个方法去应对
resource 创建包方式
[UTCTF2020]file header
解决问题:Unable to connect to Redis
IPv4 exercises
Installing postgresql11 database under centos7



![[SUCTF 2019]Game](/img/9c/362117a4bf3a1435ececa288112dfc.png)


![[P2P] local packet capturing](/img/4e/e1b60e74bc4c44e453cc832283a1f4.png)


