hi-ravii / LeetCode-Daily-Solution

1 stars 0 forks source link

Cpp Solution #2

Open Mgaurav01 opened 2 years ago

Mgaurav01 commented 2 years ago

class Solution { public: void reversePreOrder(TreeNode* root , vector &ans , int l) { if(!root) return ;

  if(l == ans.size())
     ans.push_back(root->val);

  reversePreOrder(root->right , ans , l + 1);
  reversePreOrder(root->left , ans , l + 1);

}
vector<int> rightSideView(TreeNode* root) {

  vector<int>ans;

  reversePreOrder(root,ans ,0);
  return ans;
}

};

hi-ravii commented 2 years ago

tq