当前位置:网站首页>Leetcode题库78. 子集(递归 c实现)
Leetcode题库78. 子集(递归 c实现)
2022-04-23 09:24:00 【柳家山头号矿工】
思路
代码
代码来源:链接
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;
}
版权声明
本文为[柳家山头号矿工]所创,转载请带上原文链接,感谢
https://blog.csdn.net/dc12499574/article/details/124358656
边栏推荐
- #yyds干货盘点#ubuntu18.0.4安装mysql并解决ERROR 1698: Access denied for user ''root''@''localhost''
- Thread scheduling (priority)
- Applet in wechat and app get current ()
- ATSS(CVPR2020)
- Go language self-study series | golang structure pointer
- Machine learning (VI) -- Bayesian classifier
- Production practice elk
- I don't understand time, timestamp and time zone. Look at this article
- Kettle experiment (III)
- Kettle experiment
猜你喜欢
DVWA range practice record
Kettle experiment
Write down the post order traversal of the ~ binary tree
Base de la technologie électronique numérique 3.1 aperçu du circuit de porte, 3.2 circuit de porte à diode semi - conductrice
[reading notes] Chapter 5 conditional statements, circular statements and block statements of Verilog digital system design tutorial (with answers to thinking questions)
Emuelec compilation summary
SAP 101K 411k inventory change
How to protect open source projects from supply chain attacks - Security Design (1)
【SQL server速成之路】数据库的视图和游标
Distributed message oriented middleware framework selection - Digital Architecture Design (7)
随机推荐
Creation of raid0 and RAID5 and Simulation of how RAID5 works
Go language self-study series | initialization of golang structure
Using JS to realize a thousandth bit
npm报错 :operation not permitted, mkdir ‘C: \Program Files \node js \node_ cache _ cacache’
The most concerned occupations after 00: civil servants ranked second. What was the first?
Summary of wrong questions 1
Learn FPGA (from Verilog to HLS)
Cloud computing competition -- basic part of 2020 competition [task 3]
To remember the composition ~ the pre order traversal of binary tree
Is Zhongyan futures safe and reliable?
[C language] document operation
Chapter VIII project stakeholder management of information system project manager summary
Kettle experiment (III)
kettle实验
DMP engine work summary (2021, lightsaber)
MySQL小練習(僅適合初學者,非初學者勿進)
【SQL server速成之路】数据库的视图和游标
DVWA range practice
How does kubernetes use harbor to pull private images
STM32 and FreeRTOS stack parsing