199. 二叉树的右视图

xiaoxiao2021-02-28  19

199. 二叉树的右视图

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); } };
转载请注明原文地址: https://www.6miu.com/read-2049986.html

最新回复(0)