本着能不用全局变量就不用全局变量的原则
void dfs(struct TreeNode* root,int target,int** returnColumnSizes,int* returnSize,int count,int* path,int** res){
if(root==NULL){
return;
}
path[count++]=root->val;
target-=root->val;
if(root->right==NULL&&root->left==NULL&&target==0){
int* temp=(int*)malloc(sizeof(int)*count);
for(int i=0;i<count;i++){
temp[i]=path[i];
}
res[(*returnSize)]=temp;
(*returnColumnSizes)[(*returnSize)++]=count;
}
dfs(root->left,target,returnColumnSizes,returnSize,count,path,res);
dfs(root->right,target,returnColumnSizes,returnSize,count,path,res);
count--;
}
int** FindPath(struct TreeNode* root, int target, int* returnSize, int** returnColumnSizes){
int** res=(int**)malloc(sizeof(int*)*5000);
*returnColumnSizes=(int*)malloc(sizeof(int)*5000);
int* path=(int*)malloc(sizeof(int)*5000);
int count=0;
*returnSize=0;
dfs(root,target,returnColumnSizes,returnSize,count,path,res);
return res;
}