void preOrder( struct TreeNode* root, int* res, int* resSize )
{
if( root==NULL ) return;
res[(*resSize)++]=root->val;
preOrder(root->left, res, resSize );
preOrder(root->right, res, resSize );
}
int* preorderTraversal(struct TreeNode* root, int* returnSize) {
int* res = (int*) malloc( sizeof(int)*100 );
*returnSize=0;
preOrder( root,res,returnSize );
return res;
}
Day18二叉树的先序遍历
最新推荐文章于 2024-08-16 23:08:28 发布