当前位置:网站首页>Sword finger offer II 079 All subsets
Sword finger offer II 079 All subsets
2022-06-11 02:36:00 【Biqiliang】
The finger of the sword Offer II 079. All subsets 【 Medium question 】
Ideas :
【 iteration 】【 Binary enumeration 】
And master station 78 The question is the same 78. A subset of
Code :
class Solution {
public List<List<Integer>> subsets(int[] nums) {
// Store all subsets
List<List<Integer>> ans = new ArrayList<>();
// Store the current mask Subset of representation
List<Integer> list = new ArrayList<>();
int n = nums.length;
// Define a int Type variable mask, Through its binary form Express nums The choice of elements in , Further representation At present mask Corresponding subset
for (int mask = 0; mask < (1 << n); mask++) {
// First of all, list To empty , Improve the reusability of variables
list.clear();
// Traverse nums Array , If at present mask Number... From right to left i Bit value is 1, Description in nums The subscript in the array is i The element of is selected , Add it to list Collection
for (int i = 0; i < n; i++) {
if ((mask & (1 << i)) != 0){
list.add(nums[i]);
}
}
// Will the current mask A subset of the representation is added to ans in
ans.add(new ArrayList<>(list));
}
// All possible mask After being traversed , Got ans That is to say nums All subsets of the array
return ans;
}
}
边栏推荐
- 剑指 Offer II 079. 所有子集
- 力扣刷题篇——哈希表
- Record scroll bar position, passive, scrolltop
- 可扩/减容线程池C语言原理讲解及代码实现
- English subtitle video translated into Chinese subtitles
- 金属有机框架MOF-Al(DIBA),MOF-Zr(DIBA),MOF-Fe(DIBA)包载姜黄素/羧苄西林/MTX甲氨蝶呤/紫杉醇PTX/阿霉素DOX/顺铂CDDP/CPT喜树碱等药物
- Rewrite: kms activates office2016, 2019 and 2021 with error code: 0xc004f069
- Cyclodextrin metal organic framework( β- Cd-mof) loaded with dimercaptosuccinic acid / emodin / quercetin / sucralose / diflunisal / omeprazole (OME)
- clang-format 最全格式说明
- List 过滤、排序、校验等处理方法
猜你喜欢

Navicat Premium 15 工具自动被杀毒防护软件删除解决方法

Write my Ini configuration file error

Metal organic framework MOF Al (Diba), MOF Zr (Diba), MOF Fe (Diba) loaded with curcumin / carboxybenzylpenicillin /mtx methotrexate / paclitaxel ptx/ DOX / cisplatin cddp/cpt camptothecin and other d

Istio安装与使用

Jetpack compose scaffold and topappbar (top navigation)

ADVANCE. AI CEO Shoudong will share the compliance of cross-border e-commerce using AI technology at the 2022 emerging market brands online Summit

叶酸配体的金属有机骨架材料MOFs负载5-氟尿嘧啶,西达本胺,紫杉醇,阿霉素,柔红霉素,布洛芬,喜树碱,姜黄素,藤黄酸等小分子药物

Tests logiciels vocabulaire commun anglais

2022 simulated 100 questions and answers for crane driver (limited to bridge crane) examination

How to read PMBOK guide in 3 steps (experience + data sharing)
随机推荐
Epoll principle and Application & ET mode and lt mode
[AI weekly] AI and freeze electron microscopy reveal the structure of "atomic level" NPC; Tsinghua and Shangtang proposed the "SIM" method, which takes into account semantic alignment and spatial reso
【AI周报】AI与冷冻电镜揭示「原子级」NPC结构;清华、商汤提出「SIM」方法兼顾语义对齐与空间分辨能力
常见漏洞的防御措施整理
String operation methods: replace, delete and split strings
Core principle and code explanation of epoll reactor model
为什么有的程序员能力一般却能拿到好offer?
Optimized dispatching (thermal power, wind energy and energy storage) [matlab code implementation]
Wechat automatic red envelope grabbing source code
Colab报错:ImportError: cannot import name ‘_check_savefig_extra_args‘ from ‘matplotlib.backend_bases‘
【无标题】
剑指 Offer II 079. 所有子集
2022 simulated 100 questions and answers for crane driver (limited to bridge crane) examination
1031. 两个非重叠子数组的最大和
软件测试是否需要掌握编程能力
App test_ Summary of test points
92. actual combat of completable future
Unity animator rewind
力扣刷题篇——哈希表
查看Redis内数据,除了命令行和客户端,你还有第三种选择