File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments