当前位置:网站首页>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 !
边栏推荐
猜你喜欢
随机推荐
Operation suggestions for today's spot Silver
Technology cloud report: from robot to Cobot, human-computer integration is creating an era
[OBS] win capture requires winrt
[GUET-CTF2019]虚假的压缩包
SQL优化的魅力!从 30248s 到 0.001s
idea添加类注释模板和方法模板
3D reconstruction - stereo correction
Iterable、Collection、List 的常见方法签名以及含义
【数学笔记】弧度
[SUCTF 2019]Game
CTF daily question day43 rsa5
Rust Versus Go(哪种是我的首选语言?)
Use and analysis of dot function in numpy
leetcode:105. 从前序与中序遍历序列构造二叉树
[performance pressure test] how to do a good job of performance pressure test?
Cnopendata geographical distribution data of religious places in China
C语言航班订票系统
测试周期被压缩?教你9个方法去应对
Mysql高低版本切换需要修改的配置5-8(此处以aicode为例)
【Unity】物体做圆周运动的几个思路




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




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