Please someone help me i am getting Memory limit exceeded


  • 0
    A
    public:
    
       void comsum(vector<vector<int> > ans, vector<int> a,vector<int>& candidates,int x)
       {
           if(x==0)
           {
               ans.push_back(a);
               cout<<a.size();
               return;
           }
           
           if(candidates.size()==0)
           return ;
           
          
           a.push_back(candidates[0]);
           comsum(ans,a,candidates,x-candidates[0]);
           a.pop_back();
           
           candidates.erase(candidates.begin());
           
           comsum(ans,a,candidates,x);
           
           
           
       }
        
         
          
        vector<vector<int>> combinationSum(vector<int>& candidates, int target) {
            vector<vector<int>> ans;
            vector<int> a;
            sort(candidates.begin(),candidates.end());
            comsum(ans,a,candidates,target);
            return ans;
            
        }
    };

Log in to reply
 

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