void func(struct TreeNode* root, int* res, int* index)
{
if(NULL == root) return;
func(root->left, res, index);
func(root->right, res, index);
res[(*index)++] = root->val;
}
int* postorderTraversal(struct TreeNode* root, int* returnSize)
{
*returnSize = 0;
int* res = (int*)malloc(sizeof(int)*100);
func(root, res, returnSize);
return res;
}
【Leetcode】C语言 145. Binary Tree Postorder Traversal
最新推荐文章于 2024-11-11 20:59:17 发布