【leetcode】257. 二叉树的所有路径

void recursion(struct TreeNode* root,char** arr,int* pst,char* s){
    if(!root) return;
    char* temp=(char*)calloc(100,sizeof(char));   
    strcat(temp,s);    
    if(!(root->left) && !(root->right)){
        sprintf(temp+strlen(s),"%d",root->val);      
        arr[(*pst)++]=temp;
        return;
    }
    sprintf(temp+strlen(s),"%d->",root->val);
    printf("%s
",temp);
    recursion(root->left,arr,pst,temp);
    recursion(root->right,arr,pst,temp);
    
}
char ** binaryTreePaths(struct TreeNode* root, int* returnSize){
    char** arr=(char**)calloc(1000,sizeof(char*));
    int pst=0;
    recursion(root,arr,&pst,"");
    *returnSize=pst;
    return arr;
}
原文地址:https://www.cnblogs.com/ganxiang/p/14060069.html