Straightforward CPP


  • 0
    B
    class Solution {
        void helper(vector<int>& nums, int start, vector<int> &inter, set<vector<int>> &res) {
            if(inter.size()>1) res.insert(inter);
            for(int i=start;i<nums.size();i++) {
                if(!inter.empty() && nums[i]<inter.back()) continue;
                inter.push_back(nums[i]);
                helper(nums,i+1, inter, res);
                inter.pop_back();
            }
        }
    public:
        vector<vector<int>> findSubsequences(vector<int>& nums) {
            set<vector<int>> res;
            vector<int> inter;
            helper(nums,0,inter,res);
            return vector<vector<int>>(res.begin(),res.end());
        }
    };
    

Log in to reply
 

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