当前位置:网站首页>LeetCode-78-子集
LeetCode-78-子集
2022-06-25 18:29:00 【z754916067】
题目

思路
- 一眼回溯,先add再remove这种解法。
- 注意一下,为了防止重复,需要index记录当前已经加到哪里了。
代码
ArrayList<List<Integer>> ans = new ArrayList<>();
public List<List<Integer>> subsets(int[] nums) {
List<Integer> ll = new ArrayList<>();
//开始进入回溯
back(nums,ll,0);
return ans;
}
public void back(int[] nums,List<Integer> ll,int index){
ans.add(new ArrayList(ll));
for (int i=index;i<nums.length;i++){
if(ll.contains(nums[i])){
continue;
}else {
ll.add(nums[i]);
back(nums,ll,i+1);
ll.remove(ll.size()-1);
}
}
}
边栏推荐
- 网络安全检测与防范 测试题(四)
- Development status of China's hydrotalcite industry in 2020 and analysis of major enterprises: the market scale is rapidly increasing, and there is a large space for domestic substitution [figure]
- 焕新出发,利尔智达天下
- Training of long and difficult sentences in postgraduate entrance examination day87
- Move graph explorer to jupyterab: use ges4jupyter to connect ges and explore graphs
- 【深入理解TcaplusDB技术】Tmonitor后台一键安装
- TCP/IP 测试题(一)
- mysql事务讲解
- 利尔达蓝牙空调接收器方案助力打造更舒适的公路生活
- [deeply understand tcapulusdb technology] create a game area for document acceptance
猜你喜欢

Analysis on the market scale and pattern of contrast agents in China in 2021: Jiangsu Hengrui pharmaceutical, general electric, Yangzijiang Pharmaceutical Group, Bayer and bleco account for more than

Pycharm 使用过程中碰到问题

06 local method interface

Idea annotation color modification method (clear)
![[deeply understand tcapulusdb technology] create a game zone](/img/91/cf4eae9a4336ca407c0da805b9d909.png)
[deeply understand tcapulusdb technology] create a game zone
![Analysis on market scale and supply of China's needle coke industry in 2020 [figure]](/img/79/6b08b62be8768484f548b6e18bd810.jpg)
Analysis on market scale and supply of China's needle coke industry in 2020 [figure]

焕新出发,利尔智达天下

【深入理解TcaplusDB技术】TcaplusDB运维单据

JVM understanding

华为发布两大昇腾计划 推动AI人才发展和科研创新
随机推荐
Pycharm 使用过程中碰到问题
Training of long and difficult sentences in postgraduate entrance examination day91
. How to exit net worker service gracefully
Use pagoda to set up mqtt server
[deeply understand tcapulusdb technology] tmonitor module architecture
[in depth understanding of tcapulusdb technology] form creation and approval of document acceptance
Leetcode force buckle (Sword finger offer 26-30) 26 Substructure of tree 27 Image of binary tree 28 Symmetric binary tree 29 Print matrix 30 clockwise Stack containing min function
mysql视图讲解
【ELT.ZIP】OpenHarmony啃论文俱乐部—见证文件压缩系统EROFS
【深入理解TcaplusDB技术】TcaplusDB机型
【深入理解TcaplusDB技术】单据受理之建表审批
中金财富安全吗? 开户需要多久
[deeply understand tcapulusdb technology] transaction execution of document acceptance
2017 reading (word memory)
C generic class case
Class 02 loader subsystem
[in depth understanding of tcapulusdb technology] new models of tcapulusdb
Command records of common data types for redis cli operations
RMAN备份数据库_双重备份备份集(Duplexing Backup Sets)
【深入理解TcaplusDB技術】TcaplusDB業務數據備份