Skip to content

Latest commit

 

History

History
33 lines (29 loc) · 937 Bytes

File metadata and controls

33 lines (29 loc) · 937 Bytes

#Combination Summ 2 Practice

void funct(int ind,int target,vector<int> st, vector<vector<int>> &v,vector<int>can)
    {
            if(target==0 )
            {
                 v.push_back(st);
                  return;    
            }
           
        for(int i=ind;i<can.size();i++)
        {
            if(i>ind && can[i]==can[i-1])
                continue;
            if(can[ind]<=target)
            {
                st.push_back(can[i]);
                funct(i+1,target-can[i],st,v,can);
                st.pop_back();
            }    
        }
        
        //funct(ind+1,target,st,v,can);
    }

    vector<vector<int>> combinationSum2(vector<int>& can, int target) {
        vector<int> st;
        vector<vector<int>> v;
        sort(can.begin(),can.end());
        funct(0,target,st,v,can);
        return v;
    }