class Solution {
public:
vector<int> rightSideView(TreeNode* root) {
vector<int> res;
rSVhelp(root,res,0);
return res;
}
void rSVhelp(TreeNode *r,vector<int> &res,int depth){
if(r==NULL) return;
if(depth+1>res.size()) res.resize(depth+1);
res[depth]=r->val;
rSVhelp(r->left,res,depth+1);
rSVhelp(r->right,res,depth+1);
}
};
199. 二叉树的右视图
最新推荐文章于 2024-08-23 08:27:37 发布