当前位置:网站首页>Leetcode question bank 78 Subset (recursive C implementation)
Leetcode question bank 78 Subset (recursive C implementation)
2022-04-23 09:28:00 【Liujiashan No.1 miner】
Ideas

Code
Source code : link
int** ans;
int* ansColSize;
int ansSize;
int* t;
int tSize;
void dfs(int cur, int* nums, int numsSize) {
if (cur == numsSize) {
int* tmp = malloc(sizeof(int) * tSize);
memcpy(tmp, t, sizeof(int) * tSize);
ansColSize[ansSize] = tSize;
ans[ansSize++] = tmp;
return;
}
t[tSize++] = nums[cur];
dfs(cur + 1, nums, numsSize);
tSize--;
dfs(cur + 1, nums, numsSize);
}
int** subsets(int* nums, int numsSize, int* returnSize, int** returnColumnSizes) {
ans = malloc(sizeof(int*) * (1 << numsSize));
ansColSize = malloc(sizeof(int) * (1 << numsSize));
t = malloc(sizeof(int) * numsSize);
*returnSize = 1 << numsSize;
ansSize = tSize = 0;
dfs(0, nums, numsSize);
*returnColumnSizes = ansColSize;
return ans;
}
版权声明
本文为[Liujiashan No.1 miner]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230923528736.html
边栏推荐
- Flutter 的加载动画这么玩更有趣
- kettle实验
- Operation not allowed for a result set of type resultset TYPE_ FORWARD_ ONLY. Explain in detail
- [reading notes] Chapter 5 conditional statements, circular statements and block statements of Verilog digital system design tutorial (with answers to thinking questions)
- Program, process, thread; Memory structure diagram; Thread creation and startup; Common methods of thread
- 考研线性代数常见概念、问题总结
- Number theory to find the sum of factors of a ^ B (A and B are 1e12 levels)
- Using JS to realize a thousandth bit
- Two ways for flutter providers to share data
- About CIN, scanf and getline, getchar, CIN Mixed use of getline
猜你喜欢

Pre parsing of JS

Kettle experiment

机器学习(六)——贝叶斯分类器

数据清洗 ETL 工具Kettle的安装

亚马逊云科技入门资源中心,从0到1轻松上云
![[Luke V0] verification environment 2 - Verification Environment components](/img/aa/820000a52bc493a0734ff0eb76f536.png)
[Luke V0] verification environment 2 - Verification Environment components

Chapter VIII project stakeholder management of information system project manager summary

三、6【Verilog HDL】基础知识之门级建模

112. Path sum

Base de la technologie électronique numérique 3.1 aperçu du circuit de porte, 3.2 circuit de porte à diode semi - conductrice
随机推荐
Kettle experiment (III)
kernel-pwn学习(3)--ret2user&&kernel ROP&&QWB2018-core
亚马逊云科技入门资源中心,从0到1轻松上云
JS and how to judge custom attributes in H5
Set the maximum width of the body, but why does the background color of the body cover the whole page?
I don't understand time, timestamp and time zone. Look at this article
Enter "net start MySQL" and "system error 5. Access denied" appears. Detailed explanation of the problem
Matlab draw five-star red flag
Pre parsing of JS
How does kubernetes use harbor to pull private images
LGB, XGB, cat, k-fold cross validation
[C language] document operation
Employee probation application (Luzhou Laojiao)
kernel-pwn学习(4)--Double Fetch&&0CTF2018-baby
NPM reports an error: operation not allowed, MKDIR 'C: \ program files \ node JS \ node_ cache _ cacache’
How to protect open source projects from supply chain attacks - Security Design (1)
Kettle experiment (III)
《数字电子技术基础》3.1 门电路概述、3.2 半导体二极管门电路
Kettle experiment
OpenCV中的图像处理 —— 轮廓入门+轮廓特征