C++ solution

  • 0
    class Solution {
        void update(TreeNode* root, vector<int> & result, int level){
            if(!root) return;
            if(level==result.size()) result.push_back( root -> val );
            if(root->right) update( root->right, result, level+1);
            if(root->left) update( root->left, result, level+1);
        vector<int> rightSideView(TreeNode* root) {
            vector<int> result;
            update(root, result, 0);
            return result;

    My first post ;)

Log in to reply

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