当前位置:网站首页>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
边栏推荐
- 《数字电子技术基础》3.1 门电路概述、3.2 半导体二极管门电路
- 112. 路径总和
- RSA 加密解密签名验签
- 亚马逊云科技入门资源中心,从0到1轻松上云
- Pre parsing of JS
- Number theory to find the sum of factors of a ^ B (A and B are 1e12 levels)
- web页面如何渲染
- Image processing in opencv -- Introduction to contour + contour features
- Acquisition of DOM learning elements JS
- Go language learning notes - exception handling | go language from scratch
猜你喜欢
Kettle experiment
Number of islands
Go language learning notes - slice, map | go language from scratch
如何实现根据照片获取地理位置及如何防御照片泄漏地理位置
亚马逊云科技入门资源中心,从0到1轻松上云
Kettle experiment (III)
501. Mode in binary search tree
Canary publishing using ingress
Go language learning notes - structure | go language from scratch
SAP 101K 411k inventory change
随机推荐
501. 二叉搜索树中的众数
Chapter VIII project stakeholder management of information system project manager summary
To remember the composition ~ the pre order traversal of binary tree
Open services in the bottom bar of idea
kernel-pwn学习(4)--Double Fetch&&0CTF2018-baby
DVWA range practice
js 原型链的深入
【SQL server速成之路】数据库的视图和游标
Go language learning notes - exception handling | go language from scratch
On array replication
Data visualization: use Excel to make radar chart
Failed to download esp32 program, prompting timeout
LeetCode396. Rotate array
Employee probation application (Luzhou Laojiao)
《數字電子技術基礎》3.1 門電路概述、3.2 半導體二極管門電路
Rembg split mask
Node installation
Installation of data cleaning ETL tool kettle
Image processing in opencv -- Introduction to contour + contour features
AQS & reentrantlock implementation principle