/** * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param root TreeNode类 the root of binary tree * @return int整型二维数组 * @return int* returnSize 返回数组行数 * @return int** returnColumnSizes 返回数组列数 */ int count1[100]; int count2[100]; int count3[100]; static int i1=0; static int i2=0; static int i3=0; int num[3]; int getSize(struct TreeNode*root) { if(root==NULL) { return 0; } int m=0; int n=0; m=getSize(root->left); n=getSize(root->right); return m+n+1; } void preorder(struct TreeNode* root, int*count) { if (root) { count[i1] = root->val; printf("%d",i1); i1=i1+1; preorder(root->left, count); preorder(root->right, count); } } void inorder(struct TreeNode* root,int*count) { if (root != NULL) { inorder(root->left,count); count[i2] =root->val; printf("%d",i2); i2++; inorder(root->right,count); } } void posorder(struct TreeNode* root,int*count) { if (root != NULL) { outorder(root->left, count); outorder(root->right, count); count[i3++]= root->val; printf("%d",i3); } } int** threeOrders(struct TreeNode* root, int* returnSize, int** returnColumnSizes ) { // write code here preorder(root, count1); inorder(root, count2); posorder(root, count3); *returnSize=3; int**ret=(int**)malloc(3*sizeof(int*)); ret[0]=count1; ret[1]=count2; ret[2]=count3; num[0]=getSize(root); num[1]=getSize(root); num[2]=getSize(root); *returnColumnSizes=num; return ret; }