当前位置:网站首页>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
边栏推荐
- How to render web pages
- Using sqlmap injection to obtain the account and password of the website administrator
- ATSS(CVPR2020)
- kernel-pwn学习(3)--ret2user&&kernel ROP&&QWB2018-core
- 112. Path sum
- Chapter VIII project stakeholder management of information system project manager summary
- I don't understand time, timestamp and time zone. Look at this article
- OpenCV中的图像处理 —— 轮廓入门+轮廓特征
- 成功的DevOps Leader 应该清楚的3个挑战
- tsdf +mvs
猜你喜欢
《信息系统项目管理师总结》第八章 项目干系人管理
三、6【Verilog HDL】基础知识之门级建模
NPM reports an error: operation not allowed, MKDIR 'C: \ program files \ node JS \ node_ cache _ cacache’
DVWA range practice
LeetCode 1611. The minimum number of operations to make an integer 0
数据清洗 ETL 工具Kettle的安装
Base de la technologie électronique numérique 3.1 aperçu du circuit de porte, 3.2 circuit de porte à diode semi - conductrice
Exclusive thoughts and cases of JS
Where is int a = 1 stored
108. Convert an ordered array into a binary search tree
随机推荐
JS node operation, why learn node operation
Production practice elk
Kettle experiment (III)
RSA encryption and decryption signature verification
Two ways for flutter providers to share data
On array replication
STM32 and FreeRTOS stack parsing
AQS & reentrantlock implementation principle
Data visualization: use Excel to make radar chart
Creation of raid0 and RAID5 and Simulation of how RAID5 works
【读书笔记】《Verilog数字系统设计教程》 第5章 条件语句、循环语句和块语句(附思考题答案)
高薪程序员&面试题精讲系列91之Limit 20000加载很慢怎么解决?如何定位慢SQL?
RSA 加密解密签名验签
数据清洗 ETL 工具Kettle的安装
kernel-pwn学习(3)--ret2user&&kernel ROP&&QWB2018-core
js 原型链的深入
员工试用期转正申请书(泸州老窖)
Give the method of instantiating the object to the new object
重载、重写、隐藏的对比
[boutique] using dynamic agent to realize unified transaction management II