题解 | #牛群仰视图#
牛群仰视图
https://www.nowcoder.com/practice/0f37a18320c4466abf3a65819592e8be
/** * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param root TreeNode类 * @return int整型一维数组 * @return int* returnSize 返回数组行数 */ void dfs(struct TreeNode* root,int *nums,int *length){ if(!root) return; if(root->left==NULL&&root->right==NULL){ nums[(*length)++]=root->val; } dfs(root->left,nums,length); dfs(root->right,nums,length); } int* bottomView(struct TreeNode* root, int* returnSize ) { // write code here int *res = (int*)malloc(sizeof(int) * 1500); int length = 0; dfs(root,res,&length); *returnSize = length; return res; }