What wrong is here?


  • 0
    X
    class Solution
    {
    public:
    
        vector<string> binaryTreePaths(TreeNode* root)
        {
    
            static vector<string> vec;
    
            if (root==NULL) return vec;
            static int a[300],r=0,cnt=0;
            int i;
            if (root->left==NULL && root->right==NULL)
            {
                ostringstream s1;
                for (i=0; i<r; ++i)
                    s1<<a[i]<<"->";
                s1<<root->val;
    
                vec.push_back(s1.str());
            }
    
            a[r++]=root->val;
            if (root->left!=NULL) binaryTreePaths(root->left);
            if (root->right!=NULL) binaryTreePaths(root->right);
            --r;
            return vec;
    
        }
    };

Log in to reply
 

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