当前位置:网站首页>Topic39——78. subset
Topic39——78. subset
2022-06-29 20:56:00 【_ Cabbage_】
subject : Give you an array of integers nums , Elements in an array Different from each other . Returns all possible subsets of the array ( Power set ).
Solution set You can't Contains a subset of repetitions . You can press In any order Returns the solution set .
Example 1:
Input :nums = [1,2,3]
Output :[[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]
Example 2:
Input :nums = [0]
Output :[[],[0]]
Tips :
1 <= nums.length <= 10
-10 <= nums[i] <= 10
nums All elements in Different from each other
backtracking :
class Solution {
public List<List<Integer>> subsets(int[] nums) {
List<List<Integer>> res = new ArrayList<>();
List<Integer> list = new ArrayList<>();
res.add(list);
trySub(nums, 0, res, list);
return res;
}
public void trySub(int[] nums, int index, List<List<Integer>> res, List<Integer> list) {
if(index >= nums.length)
return;
for(int i = index; i < nums.length; i++) {
list.add(nums[i]);
trySub(nums, i + 1, res, list);
res.add(new ArrayList<>(list));
list.remove(list.size() - 1);
}
}
}
边栏推荐
- Curl download example
- 不同系统下的文件层级符号小结
- verilog实现DDS波形发生器模块,可实现频率、相位可调,三种波形
- Is it safe to open an account with flush for stock trading?
- "Operation and maintenance department has Xiao Deng" to review and analyze file and folder access rights
- Lexin interview process
- Reinforcement learning weekly (issue 51): integration of PAC, ilql, RRL & model free reinforcement learning into micro grid control: overview and Enlightenment
- Leading by 11%, Huawei cloud sky chip AI solver once again topped the international authoritative list
- 「运维有小邓」审核并分析文件和文件夹访问权限
- 2021 CCPC Harbin E. power and modulo (thinking questions)
猜你喜欢

智能门锁主流品牌有哪些?选购门锁时要注重产品的哪些特性?
![Navigation exercises [microcomputer principles] [exercises]](/img/79/8311a409113331e72f650a83351b46.png)
Navigation exercises [microcomputer principles] [exercises]

"Xiaodeng" active directory password expiration notification function is available for operation and maintenance

In depth good article | yolov5+deepsort multi-target tracking in-depth interpretation and testing (including source code)

解释PBR纹理贴图(texture-maps)

leetcode:724. 寻找数组的中心下标

一颗新的北极星已经升起!

CORDIC based Signal Processor desgn

verilog实现串口通信发送到数码管

Gstreamer应用开发实战指南(五)
随机推荐
[today in history] June 29: SGI and MIPS merged; Microsoft acquires PowerPoint developer; News corporation sells MySpace
Practical guide to GStreamer application development (V)
Bigder: Automation Test Engineer
Win10 sets automatic dial-up networking task to realize automatic reconnection after startup and disconnection
leetcode:307. 区域和检索 - 数组可修改
PostgreSQL每周新聞—6月22日
How can colleges and universities build future oriented smart campus based on cloud native? Full stack cloud native vs traditional technology architecture
Cantata version 9.5 has officially passed the sgs-t Ü V certification and conforms to all major software safety standards
HAproxy + Keepalive实现LDAP代理服务
"Xiaodeng" active directory password expiration notification function is available for operation and maintenance
STL教程6-deque、stack、queue、list容器
路由汇总带来的三层环路-解决实验
Flutter BottomNavigationBar带有页面切换示例
A new Polaris has risen!
量子机器学习的基础和应用:一个简明文献综述
透过华为军团看科技之变(五):智慧园区
2021 CCPC Harbin J. local minimum (thinking question)
[a must for reptiles - > scrapy framework from black iron to king] first chapter - detailed explanation of 10000 character blog posts (recommended Collection)
leetcode:370. 区间加法
Analysis of the factors affecting the transmission signal of the conductive slip ring