c++ 6ms recursion solution


  • 0
    E

    class Solution {
    public:
    vector<int> rightSideView(TreeNode* root) {
    if(root==NULL)return result;
    dfs(root,0);
    return result;
    }
    private:
    vector<int> result;
    void dfs(TreeNode* tn,int dep){
    if(tn==NULL)return ;
    if(dep == result.size()){
    result.push_back(tn->val);
    }
    dfs(tn->right,dep+1);
    dfs(tn->left,dep+1);
    }
    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.