复试的人真的搞心态啊,怎么能这么变态,刷题这么块。哭了。
要是难一点的重复问题还是写for循环好点。
/**
* 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 temp[20];
void dfs(int* nums,int numsSize,int** array,int* returnSize,int* column,int index,int count,int last){
if(index>numsSize) return;
if(index==numsSize && count <=1) return;
if(index==numsSize ){
column[*returnSize]=count;
array[*returnSize]=(int*)malloc(sizeof(int)*count);
for(int i=0;i<count;i++) array[*returnSize][i]=temp[i];
(*returnSize)++;
return;
}
if(nums[index]>=last ){
temp[count]=nums[index];
dfs(nums,numsSize,array,returnSize,column,index+1,count+1,nums[index]);
}
if(nums[index]!=last ){
dfs(nums,numsSize,array,returnSize,column,index+1,count,last);
}
}
int** findSubsequences(int* nums, int numsSize, int* returnSize, int** returnColumnSizes) {
*returnSize=0;
int** array=(int**)malloc(sizeof(int*)*40000);
int* column=(int*)malloc(sizeof(int)*40000);
int last=INT_MIN;
dfs(nums,numsSize,array,returnSize,column,0,0,last);
*returnColumnSizes=column;
return array;
}
结果:
标签:numsSize,index,nums,int,returnSize,序列,array,递减,491 From: https://www.cnblogs.com/llllmz/p/18063298