当前位置:网站首页>Leetcode78. Subset
Leetcode78. Subset
2022-08-08 04:29:00 【Java Full Stack R&D Alliance】
题目传送地址:https://leetcode.cn/problems/subsets/
运行效率:
代码如下 递归解法
class Solution {
public List<List<Integer>> subsets(int[] nums) {
List<List<Integer>> res = new ArrayList<>();
int lastNum = nums[nums.length - 1]; //the last element of the current array
//处理边界情况
if(nums.length==1){
List<Integer> list = new ArrayList<>();
list.add(lastNum);
res.add(Arrays.asList());
res.add(list);
return res;
}
int[] subArray = Arrays.copyOf(nums, nums.length - 1);
List<List<Integer>> subsets = subsets(subArray);
res.addAll(subsets); //A subset of the previous array is also part of the subset that belongs to the new array
for (int i = 0; i < subsets.size(); i++) {
List<Integer> list1 = new ArrayList<>(subsets.get(i));
list1.add(lastNum);
res.add(list1);
}
return res;
}
}
边栏推荐
- 使用 Presto 和 Alluxio 在 AWS 上搭建高性能平台来支持实时游戏服务
- 响应式pbootcms模板健身器械类网站
- 项目分析(嵌入式产品中的硬件设计、生产)
- 高薪程序员&面试题精讲系列134之微服务网关有哪些限流算法?如何实现限流?
- C语言-分值和循环语句
- 实现Express中间件原理
- Inside outside l think MindSpore AI framework, heavy industry gathering, huawei big extraordinary path of the model
- This article will give you a thorough understanding of synchronized and Lock
- cube-studio 部署过程
- 一文带你彻底了解synchronized 和 Lock
猜你喜欢

手把手教你手撕SPF生成树(OSPF区域内防环)

awk语法-03-awk表达式(if语句、while循环、for循环)、awk中执行shell命令

MySQL4(多表查询)

L3-006 迎风一刀斩

Young freshmen who yearn for open source | The guide to avoiding pits from open source to employment is here!

数据库篇复习篇

Research on Blind Recognition of Digital Modulated Signal Based on MindSpore Framework

A line of code counts the number of occurrences of the specified string in the text

NLP之基本介绍

ToDesk企业版上新 | 十大新功能,让企业远控更安全、更便捷、更流畅
随机推荐
数据库缓冲区高速缓存中块的类型
y90.第六章 微服务、服务网格及Envoy实战 -- 服务网格基础(一)
C language minesweeping
Codeforces Round #684 (Div. 1)
Inside outside l think MindSpore AI framework, heavy industry gathering, huawei big extraordinary path of the model
MySQL——索引与事务
VSCode打开 C(嵌入式) 工程的一些记录
使用ffmpeg解码音频sdl(push)播放
中国科学院金属研究所科研课题获华为技术认证,助力材料学发展新范式!
L3-005 垃圾箱分布
06 tp6 的数据更新(改)及删除 《ThinkPHP6 入门到电商实战》
leetcode: 874. 模拟行走机器人
32. 你知道Redis的字符串是怎么实现的吗?
sessionStorage在不同页签中的数据是否共享问题及解决思路
Heterogeneous on the Graph paper to share 】 【 small sample learning: HG - Meta: Graph Meta - learning over Heterogeneous Graphs
leetcode: 122. 买卖股票的最佳时机 II
国内最主流的5大项目工时管理系统
torch.view()函数用法
二维码生成工具
NetCore使用Dapper查询数据