当前位置:网站首页>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 !
边栏推荐
- Most elements
- You Li takes you to talk about C language 6 (common keywords)
- buuctf misc USB
- Gslx680 touch screen driver source code analysis (gslx680. C)
- 海思芯片(hi3516dv300)uboot镜像生成过程详解
- 图解GPT3的工作原理
- Use and analysis of dot function in numpy
- [UVM basics] summary of important knowledge points of "UVM practice" (continuous update...)
- vus.SSR在asynData函数中请求数据的注意事项
- 【webrtc】m98 screen和window采集
猜你喜欢

Most elements

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

探索Cassandra的去中心化分布式架构

2022制冷与空调设备运行操作复训题库及答案

Problem solving: unable to connect to redis

JSON introduction and JS parsing JSON

Explore Cassandra's decentralized distributed architecture

leetcode:105. 从前序与中序遍历序列构造二叉树

leetcode:105. Constructing binary trees from preorder and inorder traversal sequences
![[GUET-CTF2019]虚假的压缩包](/img/a2/7da2a789eb49fa0df256ab565d5f0e.png)
[GUET-CTF2019]虚假的压缩包
随机推荐
[guess-ctf2019] fake compressed packets
Problem solving: unable to connect to redis
Operation suggestions for today's spot Silver
知识点滴 - 关于苹果认证MFI
Rust Versus Go(哪种是我的首选语言?)
Solve could not find or load the QT platform plugin "xcb" in "
Ansible
测试周期被压缩?教你9个方法去应对
mysql多列索引(组合索引)特点和使用场景
Resource create package method
A bit of knowledge - about Apple Certified MFI
Pytorch parameter initialization
Technology cloud report: from robot to Cobot, human-computer integration is creating an era
misc ez_ usb
[UTCTF2020]file header
通信设备商,到底有哪些岗位?
[UVM practice] Chapter 1: configuring the UVM environment (taking VCs as an example), run through the examples in the book
图解GPT3的工作原理
智联+影音,AITO问界M7想干翻的不止理想One
Most elements