当前位置:网站首页>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 !
边栏推荐
- leanote私有云笔记搭建
- 2022-07-06: will the following go language codes be panic? A: Meeting; B: No. package main import “C“ func main() { var ch chan struct
- 今日现货白银操作建议
- Route jump in wechat applet
- 2022焊工(初级)判断题及在线模拟考试
- [SUCTF 2019]Game
- [2022 ACTF]web题目复现
- Jenkins远程构建项目超时的问题
- Leetcode 43 String multiplication (2022.02.12)
- CentOS7下安装PostgreSQL11数据库
猜你喜欢
随机推荐
What are the positions of communication equipment manufacturers?
微博发布案例
[unity] several ideas about circular motion of objects
[UVM practice] Chapter 2: a simple UVM verification platform (2) only driver verification platform
LeetCode 40:组合总和 II
[2022 ciscn] replay of preliminary web topics
Linux server development, SQL statements, indexes, views, stored procedures, triggers
Common validation comments
Cnopendata geographical distribution data of religious places in China
242. Bipartite graph determination
[UVM basics] summary of important knowledge points of "UVM practice" (continuous update...)
php导出百万数据
今日现货白银操作建议
为什么要了解现货黄金走势?
知识点滴 - 关于苹果认证MFI
[UTCTF2020]file header
nacos
2022焊工(初级)判断题及在线模拟考试
Jenkins远程构建项目超时的问题
快速使用 Jacoco 代码覆盖率统计









![[GUET-CTF2019]虚假的压缩包](/img/a2/7da2a789eb49fa0df256ab565d5f0e.png)