当前位置:网站首页>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 !
边栏推荐
- [P2P] local packet capturing
- Technology cloud report: from robot to Cobot, human-computer integration is creating an era
- Live online system source code, using valueanimator to achieve view zoom in and out animation effect
- [experience sharing] how to expand the cloud service icon for Visio
- What are the positions of communication equipment manufacturers?
- Leanote private cloud note building
- Kbu1510-asemi power supply special 15A rectifier bridge kbu1510
- 解决问题:Unable to connect to Redis
- Button wizard script learning - about tmall grabbing red envelopes
- 面试结束后,被面试官在朋友圈吐槽了......
猜你喜欢
随机推荐
2022茶艺师(初级)考试题模拟考试题库及在线模拟考试
Visualization Document Feb 12 16:42
dash plotly
【webrtc】m98 screen和window采集
Wx is used in wechat applet Showtoast() for interface interaction
科技云报道:从Robot到Cobot,人机共融正在开创一个时代
idea添加类注释模板和方法模板
vus. Precautions for SSR requesting data in asyndata function
[guess-ctf2019] fake compressed packets
Cnopendata American Golden Globe Award winning data
Technology cloud report: from robot to Cobot, human-computer integration is creating an era
【webrtc】m98 screen和window采集
Linux server development, MySQL stored procedures, functions and triggers
[UVM basics] summary of important knowledge points of "UVM practice" (continuous update...)
php导出百万数据
@component(““)
JSON introduction and JS parsing JSON
pytest+allure+jenkins安装问题:pytest: error: unrecognized arguments: --alluredir
Iterable、Collection、List 的常见方法签名以及含义
Idea add class annotation template and method template