当前位置:网站首页>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 !
边栏推荐
- 2022年全国最新消防设施操作员(初级消防设施操作员)模拟题及答案
- Live online system source code, using valueanimator to achieve view zoom in and out animation effect
- Six methods of flattening arrays with JS
- nacos
- [2022 ACTF]web题目复现
- [guess-ctf2019] fake compressed packets
- 3D reconstruction - stereo correction
- Info | webrtc M97 update
- IO stream file
- KBU1510-ASEMI电源专用15A整流桥KBU1510
猜你喜欢
随机推荐
探索Cassandra的去中心化分布式架构
ASEMI整流桥RS210参数,RS210规格,RS210封装
通信设备商,到底有哪些岗位?
Explore Cassandra's decentralized distributed architecture
Jenkins remote build project timeout problem
为什么要了解现货黄金走势?
Codeforces Global Round 19
Six methods of flattening arrays with JS
Write CPU yourself -- Chapter 9 -- learning notes
numpy中dot函数使用与解析
[2022 ciscn] replay of preliminary web topics
pytest+allure+jenkins環境--填坑完畢
KBU1510-ASEMI电源专用15A整流桥KBU1510
You Li takes you to talk about C language 6 (common keywords)
IO流 file
Sign up now | oar hacker marathon phase III, waiting for your challenge
[UVM practice] Chapter 1: configuring the UVM environment (taking VCs as an example), run through the examples in the book
[experience sharing] how to expand the cloud service icon for Visio
Most elements
Qt学习27 应用程序中的主窗口

![[2022 actf] Web Topic recurrence](/img/e4/ab9a1771489d751ee73a79f151d374.png)


![[mathematical notes] radian](/img/43/2af510adb24fe46fc0033d11d60488.jpg)



