Skip to content

Commit c1e5744

Browse files
committed
sol 94
1 parent 82eac5b commit c1e5744

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

c_code/94_inorderTraversal.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* struct TreeNode {
4+
* int val;
5+
* struct TreeNode *left;
6+
* struct TreeNode *right;
7+
* };
8+
*/
9+
10+
/**
11+
* Note: The returned array must be malloced, assume caller calls free().
12+
*/
13+
14+
void inorderRecruTraver(struct TreeNode* root, int *res, int* returnSize)
15+
{
16+
if (root == NULL) { return; }
17+
18+
inorderRecruTraver(root->left, res, returnSize);
19+
res[*returnSize] = root->val;
20+
*returnSize += 1;
21+
inorderRecruTraver(root->right, res, returnSize);
22+
return;
23+
}
24+
25+
int* inorderTraversal(struct TreeNode* root, int* returnSize)
26+
{
27+
int *res = (int*)malloc(101 * sizeof(int));
28+
if (res == NULL) { return NULL; }
29+
*returnSize = 0;
30+
inorderRecruTraver(root, res, returnSize);
31+
return res;
32+
}

0 commit comments

Comments
 (0)