Skip to content

feat: problem #90 Add C++ implementation #172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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