/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
/**
* Note: The returned array must be malloced, assume caller calls free().
*/
void postorder(struct TreeNode* root,int* temp,int* i){
if(!root) return;
postorder(root->left,temp,i);
postorder(root->right,temp,i);
temp[(*i)++]=root->val;
}
int* postorderTraversal(struct TreeNode* root, int* returnSize) {
int* temp=(int*)malloc(sizeof(int)*100);
for(int i=0;i<100;i++) temp[i]=-1;
int i=0;
postorder(root,temp,&i);
*returnSize=i;
return temp;
}
结果:
标签:遍历,TreeNode,struct,temp,int,145,二叉树,root,postorder From: https://www.cnblogs.com/llllmz/p/18045770