class Solution {
public:
vector<int> largestValues(TreeNode* root) {
vector<int> res;
lVhelp(root,res,0);
return res;
}
void lVhelp(TreeNode *r,vector<int> &res,int depth){
if(r==NULL) return;
if(depth+1>res.size()) res.push_back(0x80000000);
res[depth]=max(r->val,res[depth]);
lVhelp(r->left,res,depth+1);
lVhelp(r->right,res,depth+1);
}
};
515. 在每个树行中找最大值
最新推荐文章于 2024-05-01 15:20:03 发布