Skip to content

Commit

Permalink
feat: problem azl397985856#90 Add C++ implementation (azl397985856#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
raof01 authored and azl397985856 committed Sep 13, 2019
1 parent 25985e2 commit ed344b3
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions problems/90.subsets-ii.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ Output:

## 代码

* 语言支持:JS,C++

JavaScript Code:

```js


Expand Down Expand Up @@ -104,6 +108,30 @@ var subsetsWithDup = function(nums) {
return list;
};
```
C++ Code:

```C++
class Solution {
private:
void subsetsWithDup(vector<int>& nums, size_t start, vector<int>& tmp, vector<vector<int>>& res) {
res.push_back(tmp);
for (auto i = start; i < nums.size(); ++i) {
if (i > start && nums[i] == nums[i - 1]) continue;
tmp.push_back(nums[i]);
subsetsWithDup(nums, i + 1, tmp, res);
tmp.pop_back();
}
}
public:
vector<vector<int>> subsetsWithDup(vector<int>& nums) {
auto tmp = vector<int>();
auto res = vector<vector<int>>();
sort(nums.begin(), nums.end());
subsetsWithDup(nums, 0, tmp, res);
return res;
}
};
```
## 相关题目
Expand Down

0 comments on commit ed344b3

Please sign in to comment.