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; }