Output Limit Error


  • 0
    Y

    Below is my recursive solution,but i kept getting “Output Limit Error”,can somebody help me here?

    class Solution {
        public:
            vector<vector<int> > combinationSum(vector<int> &candidates, int target) {
                sort(candidates.begin(),candidates.end());
                vector<vector<int>> vec;
                int n=candidates.size();
                for(int i=n-1;i>=0;i--){
                    if(candidates[i]==target){
                        vector<int> tp;
                        tp.push_back(target);
                        vec.push_back(tp);
                    }
                    else if(candidates[i]<target){
                    vector<vector<int >> ret=combinationSum(candidates,target-candidates[i]);
                    int size=ret.size();
                    for(int j=0;j<size;j++){
                        vector<int> tmp=ret[j];
                        tmp.push_back(candidates[i]);
                        vec.push_back(tmp);
                    }
                    }
                }
                return vec;
            }
        };

Log in to reply
 

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