当前位置:网站首页>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 !
边栏推荐
- Iterable、Collection、List 的常见方法签名以及含义
- Wx is used in wechat applet Showtoast() for interface interaction
- Most elements
- Rxjs - observable doesn't complete when an error occurs - rxjs - observable doesn't complete when an error occurs
- nacos
- 2022年全国最新消防设施操作员(初级消防设施操作员)模拟题及答案
- Few-Shot Learning && Meta Learning:小样本学习原理和Siamese网络结构(一)
- Value sequence (subsequence contribution problem)
- What is the difference between TCP and UDP?
- Mysql高低版本切换需要修改的配置5-8(此处以aicode为例)
猜你喜欢

mysql多列索引(组合索引)特点和使用场景

自定义类加载器加载网络Class

Few-Shot Learning && Meta Learning:小样本学习原理和Siamese网络结构(一)
![[UTCTF2020]file header](/img/e3/818e2d531a06ab90de189055f634ad.png)
[UTCTF2020]file header

misc ez_ usb

Detailed explanation of uboot image generation process of Hisilicon chip (hi3516dv300)

探索干货篇!Apifox 建设思路

@component(““)

ASEMI整流桥RS210参数,RS210规格,RS210封装

面试结束后,被面试官在朋友圈吐槽了......
随机推荐
Leanote private cloud note building
大视频文件的缓冲播放原理以及实现
[SUCTF 2019]Game
A bit of knowledge - about Apple Certified MFI
[mathematical notes] radian
Wechat applet data binding multiple data
【webrtc】m98 screen和window采集
Tianqing sends instructions to bypass the secondary verification
Asemi rectifier bridge rs210 parameters, rs210 specifications, rs210 package
Is the test cycle compressed? Teach you 9 ways to deal with it
JS plot flot application - simple curve
2022-07-06:以下go语言代码是否会panic?A:会;B:不会。 package main import “C“ func main() { var ch chan struct
[performance pressure test] how to do a good job of performance pressure test?
Weibo publishing cases
Jenkins远程构建项目超时的问题
Common method signatures and meanings of Iterable, collection and list
[UVM basics] summary of important knowledge points of "UVM practice" (continuous update...)
What is the difference between TCP and UDP?
Linux server development, MySQL stored procedures, functions and triggers
C语言航班订票系统