what is wrong with this code. help me out plz


  • 0
    P
    class Solution {
    public:
            void path(TreeNode *root,vector<string> &result,string &res,int length)
            {
                if(root==NULL) return;
                res[length]=root->val;
                length++;
                if(!root->left && !root->right)
                {
                    
                    result.push_back(res);
                   
                }
                else
                {
                    path(root->left,result,res,length);
                     path(root->right,result,res,length);
                    
                }
            }
        
        vector<string> binaryTreePaths(TreeNode* root) {
            vector<string> result;
            string res;
            int length=0;
             path(root,result,res,length);
             return result;
             
            
        }
    };
    

Log in to reply
 

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