给定一个可能包含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集)。

说明:解集不能包含重复的子集。

示例:

输入: [1,2,2] 输出: [ [2], [1], [1,2,2], [2,2], [1,2], [] ]

class Solution {
public:
int len;
vector<vector<int> > res;
vector<vector<int> > subsetsWithDup(vector<int>& nums)
{
sort(nums.begin(), nums.end());
len = nums.size();
vector<int> temp;
DFS(nums, temp, 0);
return res;
} void DFS(vector<int>& nums, vector<int> temp, int pos)
{
res.push_back(temp);
for(int i = pos; i < len; i++)
{
temp.push_back(nums[i]);
DFS(nums, temp, i + 1);
temp.pop_back();
for(; i < len - 1; i++)
{
if(nums[i + 1] != nums[i])
{
break;
}
}
}
}
};

Leetcode90. Subsets II子集2的更多相关文章

  1. LeetCode90:Subsets II

    Given a collection of integers that might contain duplicates, nums, return all possible subsets. Not ...

  2. [LeetCode] Subsets II 子集合之二

    Given a collection of integers that might contain duplicates, S, return all possible subsets. Note: ...

  3. [LeetCode] 90. Subsets II 子集合之二

    Given a collection of integers that might contain duplicates, S, return all possible subsets. Note: ...

  4. 090 Subsets II 子集 II

    给定一个可能包含重复整数的列表,返回所有可能的子集(幂集).注意事项:解决方案集不能包含重复的子集.例如,如果 nums = [1,2,2],答案为:[  [2],  [1],  [1,2,2],  ...

  5. Leetcode之回溯法专题-90. 子集 II(Subsets II)

    Leetcode之回溯法专题-90. 子集 II(Subsets II) 给定一个可能包含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集). 说明:解集不能包含重复的子集. 示例: 输入 ...

  6. [leetcode]90. Subsets II数组子集(有重)

    Given a collection of integers that might contain duplicates, nums, return all possible subsets (the ...

  7. 42. Subsets && Subsets II

    Subsets Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset ...

  8. 【leetcode】Subsets II

    Subsets II Given a collection of integers that might contain duplicates, S, return all possible subs ...

  9. 【LeetCode】90. Subsets II (2 solutions)

    Subsets II Given a collection of integers that might contain duplicates, S, return all possible subs ...

随机推荐

  1. Neo4j-APOC使用总结(一)

    一.安装APOC 1.下载jar包:https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases 2.把jar包放在安装目录的plug ...

  2. 机器学习-反向传播算法(BP)代码实现(matlab)

    %% Machine Learning Online Class - Exercise 4 Neural Network Learning % Instructions % ------------ ...

  3. BOM相关知识点

    1.BOM概念:Browser Object Model 浏览器对象模型作用:提供了使用JS操作浏览器的接口 2.BOM包含了许多对象信息,包括如下这些:(1)screen 屏幕信息(2)locati ...

  4. linux 服务 启动 关闭 列表

    ##查看服务在每个级别的运行状态 chkconfig --list httpd           0:关闭  1:关闭  2:关闭  3:关闭  4:关闭  5:启用  6:关闭 bluetooth ...

  5. SpringCloud搭建分布式配置中心(基于git)

    1.简介 Spring Cloud Config.它用来为分布式系统中的基础设施和微服务提供集中化的外部配置支持,分为服务端和客户端两个部分. 其中服务端也称为分布式配置中心,他是独立的微服务应用,用 ...

  6. 阿里巴巴大数据产品最新特性介绍--机器学习PAI

    以下内容根据演讲视频以及PPT整理而成. 本次分享主要围绕以下五个方面: PAI产品简介 自定义算法上传 数加智能生态市场 AutoML2.0自动调参 AutoLearning自动学习 一.PAI产品 ...

  7. $router 跳转

    vue用$router跳转有三种方法 this.$router.push.replace.go this.$router.push() 跳转到不同的url,但这个方法回向history栈添加一个记录, ...

  8. 2019年6月份Github上最热门的开源项目排行出炉,一起来看看本月上榜的开源项目

    6月份Github上最热门的开源项目排行出炉,一起来看看本月上榜的开源项目有哪些: 1. the-art-of-command-line https://github.com/jlevy/the-ar ...

  9. Docker系列(十四):Kubernetes API和源码分析

    Kubernetes API入门 Ku8 eye开源项目

  10. mysql表时间戳字段设置

    创建时间 修改时间