C++ 4MS TRIVIAL RECURSIVE SOLUTION


  • 0
    C
    vector<int> res;
    int max=-1;
    void helper(TreeNode* root,int h){
        if(root==NULL) return;
        if(h>max){
            res.push_back(root->val);
            max=h;
        }
        helper(root->right,h+1);
        helper(root->left,h+1);
    }
    vector<int> rightSideView(TreeNode* root) {
        helper(root,0);
        return res;
    }

  • 0
    F

    Why someone down voted it, I think this is a right solution.


Log in to reply
 

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