当前位置:网站首页>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 !
边栏推荐
- 《动手学深度学习》(四) -- 卷积神经网络 CNN
- Tianqing sends instructions to bypass the secondary verification
- Installing postgresql11 database under centos7
- 通信设备商,到底有哪些岗位?
- 解决:Could NOT find KF5 (missing: CoreAddons DBusAddons DocTools XmlGui)
- After the interview, the interviewer roast in the circle of friends
- Detailed explanation of uboot image generation process of Hisilicon chip (hi3516dv300)
- Is the test cycle compressed? Teach you 9 ways to deal with it
- 解决问题:Unable to connect to Redis
- JS get all date or time stamps between two time stamps
猜你喜欢
Explore Cassandra's decentralized distributed architecture
探索Cassandra的去中心化分布式架构
Linux server development, SQL statements, indexes, views, stored procedures, triggers
What are the positions of communication equipment manufacturers?
KBU1510-ASEMI电源专用15A整流桥KBU1510
Common validation comments
[guess-ctf2019] fake compressed packets
Wechat applet data binding multiple data
2022茶艺师(初级)考试题模拟考试题库及在线模拟考试
2022焊工(初级)判断题及在线模拟考试
随机推荐
You Li takes you to talk about C language 6 (common keywords)
After the interview, the interviewer roast in the circle of friends
What is the interval in gatk4??
2022制冷与空调设备运行操作复训题库及答案
Rust Versus Go(哪种是我的首选语言?)
有 Docker 谁还在自己本地安装 Mysql ?
Operation suggestions for today's spot Silver
LeetCode 40:组合总和 II
[SUCTF 2019]Game
Linux server development, MySQL process control statement
Cnopendata American Golden Globe Award winning data
Why should we understand the trend of spot gold?
[UTCTF2020]file header
numpy中dot函数使用与解析
即刻报名|飞桨黑客马拉松第三期等你挑战
CTF daily question day43 rsa5
《动手学深度学习》(四) -- 卷积神经网络 CNN
Jenkins remote build project timeout problem
通信设备商,到底有哪些岗位?
2022茶艺师(初级)考试题模拟考试题库及在线模拟考试