
int TreeSize(struct TreeNode* root)
{
return root == NULL ? 0 : TreeSize(root->left) + TreeSize(root->right) + 1;
}
void Inorder(struct TreeNode* root,int* a,int* pi)
{
if(root == NULL)
return ;
Inorder(root->left,a,pi);
a[(*pi)++] = root->val;
Inorder(root->right,a,pi);
}
int* inorderTraversal(struct TreeNode* root, int* returnSize){
*returnSize = TreeSize(root);
int* a = (int*)malloc((*returnSize) * sizeof(int));
int i=0;
Inorder(root,a,&i);
return a;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32