char **g_res;
int idx;
#define MAXNUM 10000
void Dfs(struct TreeNode *root, char *str)
{
if (!root) {
//idx = 0;
return;
}
if (!root->left && !root->right) {
char *mid = (char *)malloc(sizeof(char) * 2);
mid[0] = root->val + '0';
mid[1] = '\0';
strcat(str, mid);
free(mid);
g_res[idx] = (char *)malloc(sizeof(char) * 100);
memcpy(g_res[idx++], str, sizeof(str));
printf("e");
return;
//memcpy(g_res[idx++], str, sizeof(str));
}
char *mid = (char *)malloc(sizeof(char) * 100);
sprintf(mid, "%d->", (root->val));
//printf("%s ", mid);
strcat(str, mid);
printf("%s", str);
free(mid);
//printf("%s", str);
Dfs(root->left, str);
Dfs(root->right, str);
}
char ** binaryTreePaths(struct TreeNode* root, int* returnSize){
g_res = (char **)malloc(sizeof(char *) * MAXNUM);
char *str = (char *)malloc(sizeof(char) * MAXNUM);
str[0] = '\0';
idx = 0;
Dfs(root, str);
*returnSize = idx;
printf("f");
return g_res;
}