leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0090.cpp (535B)


      1 class Solution {
      2   public:
      3     vector<vector<int>> subsetsWithDup(vector<int> &nums) {
      4         sort(nums.begin(), nums.end());
      5         vector<vector<int>> res = {{}, {nums[0]}};
      6 
      7         int prev = 1;
      8         for (int i = 1; i < nums.size(); i++) {
      9             int end = nums[i] == nums[i - 1] ? prev : 0;
     10             prev = res.size();
     11             for (int j = res.size() - 1; j >= end; j--) {
     12                 res.push_back(res[j]);
     13                 res.back().push_back(nums[i]);
     14             }
     15         }
     16 
     17         return res;
     18     }
     19 };