当前位置:网站首页>46. full arrangement -dfs double hundred code
46. full arrangement -dfs double hundred code
2022-06-30 06:04:00 【Mr Gao】
46. Full Permutation -dfs Shuangbai code
Give an array without duplicate numbers nums , Back to its All possible permutations . You can In any order Return to the answer .
Example 1:
Input :nums = [1,2,3]
Output :[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
Example 2:
Input :nums = [0,1]
Output :[[0,1],[1,0]]
Example 3:
Input :nums = [1]
Output :[[1]]
/** * Return an array of arrays of size *returnSize. * The sizes of the arrays are returned as *returnColumnSizes array. * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free(). */
int f1(int n){
int re=1;
while(n>=1){
re=re*n;
n--;
}
return re;
}
int re_size;
void dfs(int *nums,int numsSize,int *r,int now_size,int *t,int **re){
int i;
if(now_size==numsSize){
re[re_size]=(int *)malloc(sizeof(int )*numsSize);
for(i=0;i<numsSize;i++){
re[re_size][i]=t[i];
}
re_size++;
}
else{
for(i=0;i<numsSize;i++){
if(r[i]==0){
t[now_size]=nums[i];
r[i]=1;
dfs(nums,numsSize,r,now_size+1,t,re);
r[i]=0;
}
}
}
}
int** permute(int* nums, int numsSize, int* returnSize, int** returnColumnSizes){
int size=f1(numsSize);
int **re=(int **)malloc(sizeof(int *)*size);
*returnColumnSizes=(int *)malloc(sizeof(int)*size);
int *t=(int *)malloc(sizeof(int )*numsSize);
int r[numsSize];
int i;
re_size=0;
for(i=0;i<size;i++){
(*returnColumnSizes)[i]=numsSize;
}
for(i=0;i<numsSize;i++){
r[i]=0;
}
dfs(nums,numsSize,r,0,t,re);
*returnSize=re_size;
return re;
}
边栏推荐
- [exercise] basic practice letter graph of Blue Bridge Cup
- 从零开发 stylelint规则(插件)
- leetcode763. Divide letter interval
- Prototype and prototype chain in JS
- Attempt to redefine 'timeout' at line 2 solution
- Summary of 2 billion redis data migration
- Beauty of Refactoring: when multithreaded batch processing task lifts the beam - Universal scaffold
- PHP knowledge points
- Record a problem tracking of excessive load
- ES6解构赋值
猜你喜欢

Create priority queue

About modifying dual system default startup item settings

Who doesn't want a blog site of their own - build a blog site WordPress

What do you think of the deleted chat records? How to restore the deleted chat records on wechat?

Balanced binary tree judgment of Li Kou 110 -- classic problems

At the beginning of 2022, people who are ready to change jobs should pay attention to

Mysql database learning notes - foreign keys, table connections, subqueries, and indexes for MySQL multi table queries

Common NPM install errors
![[ansible series] fundamentals 02 module debug](/img/99/c53be8e2a42c7cb5b4a9a7ef4ad98c.jpg)
[ansible series] fundamentals 02 module debug

观察者模式、状态模式在实际工作中的使用
随机推荐
[Alibaba cloud] student growth plan answers
【数据库】事务
At the age of 32, I fell into a middle-aged crisis and finally quit naked...
电脑查看WiFi使用密码
MySQL transaction
About modifying dual system default startup item settings
Share problems solved
Who doesn't want a blog site of their own - build a blog site WordPress
Leader: who can use redis expired monitoring to close orders and get out of here!
[exercise] basic practice letter graph of Blue Bridge Cup
[OSPF] comparison between rip and OSPF
Mariadb数据库的安装与初始化
MySQL advanced SQL statement
ES6扩展运算符(...)
网络基础知识
Shenzhou ares tx6 boot logo modification tutorial
PC viewing WiFi password
Common NPM install errors
What indicators should safety service engineers pay attention to in emergency response?
There is a group of students' score {99, 85, 82, 63, 60}. To add a student's score, insert it into the score sequence and keep the descending order