void preorder(struct TreeNode* root, int* returnSize, int* a)
{
if (root == NULL)
{
return;
}
if (root != NULL)
{
a[*returnSize] = root->val;
(*returnSize)++;
preorder(root->left, returnSize, a);
preorder(root->right, returnSize, a);
}
}
int* preorderTraversal(struct TreeNode* root, int* returnSize)
{
int* a = malloc(100 * sizeof(int));
*returnSize = 0;
preorder(root, returnSize, a);
return a;
}
144. 二叉树的前序遍历
最新推荐文章于 2024-08-03 20:10:04 发布