The preorder of the binary tree traverses, do not understand what this question let me return (C language), cPP I do the opposite

binary tree preorder traversal

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
/**
 * Return an array of size *returnSize.
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* preorderTraversal(struct TreeNode* root, int* returnSize) {
    int i = 0;
    //int *arr = (int *)malloc(100*sizeof(int));
    if(root)
    {
        returnSize[iPP] = root->val;
        preorderTraversal(root->left, returnSize);
        preorderTraversal(root->right, returnSize);
    }
    
    return returnSize;
}
Feb.27,2021

Isn't there a hint in the

comment? The size of the array is * returnSize . The return value of the following function also makes it clear that it is a pointer of type int, which points to an int array of length * returnSize .

in short, you need to set the value of * returnSize before returning, which returns your own array of malloc

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e7270d-4619d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e7270d-4619d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?