/**
* 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 inorder(struct TreeNode* root,int* temp,int* i){
if(!root) return;
inorder(root->left,temp,i);
temp[(*i)++]=root->val;
inorder(root->right,temp,i);
}
int* inorderTraversal(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;
inorder(root,temp,&i);
*returnSize=i;
return temp;
}
结果:
标签:TreeNode,struct,temp,int,inorder,中序,二叉树,root,94 From: https://www.cnblogs.com/llllmz/p/18045763