当前位置:网站首页>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
边栏推荐
- LeetCode396. Rotate array
- Kettle experiment
- Applet in wechat and app get current ()
- NLLLoss+log_ SoftMax=CE_ Loss
- Cloud computing competition -- basic part of 2020 competition [task 3]
- Write down the post order traversal of the ~ binary tree
- Matlab draw five-star red flag
- Arbre de dépendance de l'emballage des ressources
- 3、 6 [Verilog HDL] gate level modeling of basic knowledge
- MySQL小练习(仅适合初学者,非初学者勿进)
猜你喜欢

Harbor enterprise image management system

108. Convert an ordered array into a binary search tree
![[C language] document operation](/img/89/b19dda13d27e37fedf6736c102245b.png)
[C language] document operation

Machine learning (VI) -- Bayesian classifier

Failed to download esp32 program, prompting timeout

MySQL小練習(僅適合初學者,非初學者勿進)

MySQL小练习(仅适合初学者,非初学者勿进)

EmuElec 编译总结

Open services in the bottom bar of idea

MySQL of database -- basic common query commands
随机推荐
Flink SQL realizes the integration of stream and batch
How does kubernetes use harbor to pull private images
Notes on xctf questions
GoLand debug go use - white record
Redis Desktop Manager for Mac
Applet error: should have URL attribute when using navigateto, redirectto or switchtab
501. Mode in binary search tree
tsdf +mvs
Two methods of building Yum source warehouse locally
Using sqlmap injection to obtain the account and password of the website administrator
Cloud computing competition -- basic part of 2020 competition [task 3]
NLLLoss+log_ SoftMax=CE_ Loss
RSA 加密解密签名验签
【读书笔记】《Verilog数字系统设计教程》 第5章 条件语句、循环语句和块语句(附思考题答案)
Program, process, thread; Memory structure diagram; Thread creation and startup; Common methods of thread
ASUS laptop can't read USB and surf the Internet after reinstalling the system
Kettle experiment
SQL used query statements
Number theory to find the sum of factors of a ^ B (A and B are 1e12 levels)
Open services in the bottom bar of idea