/** * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param root TreeNode类 * @return int整型一维数组 * @return int* returnSize 返回数组行数 */ static int a[100]; static int size=0; void preorder(struct TreeNode* root){ if(root==NULL){ }else{ a[size++]=root->val; preorder(root->left);//遍历左子树 preorder(root->right);//遍历右子树 } } int* preorderTraversal(struct TreeNode* root, int* returnSize ) { // write code here preorder(root); *returnSize=size; return a; }