Given a set of distinct integers, nums, return all possible subsets (the power set).

Note: The solution set must not contain duplicate subsets.

Example:

Input: nums = [1,2,3]
Output:
[
[3],
  [1],
  [2],
  [1,2,3],
  [1,3],
  [2,3],
  [1,2],
  []
]


class Solution {
public:
vector<vector<int>> subsets(vector<int>& nums) {
int length=nums.size();
sort(nums.begin(),nums.end());
vector<vector<int> > result;
for(int i=;i<<<length;i++)
{
vector<int> tmp; for(int j=;j<length;j++)
{ if(i&<<j)
{
tmp.push_back(nums[j]);
}
}
result.push_back(tmp);
}
return result;
} };

78[LeetCode] Subsets的更多相关文章

  1. LeetCode:Subsets I II

    求集合的所有子集问题 LeetCode:Subsets Given a set of distinct integers, S, return all possible subsets. Note: ...

  2. LeetCode Subsets II (DFS)

    题意: 给一个集合,有n个可能相同的元素,求出所有的子集(包括空集,但是不能重复). 思路: 看这个就差不多了.LEETCODE SUBSETS (DFS) class Solution { publ ...

  3. LeetCode 78. 子集(Subsets) 34

    78. 子集 78. Subsets 题目描述 给定一组不含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集). 说明: 解集不能包含重复的子集. 每日一算法2019/6/6Day 34L ...

  4. [LeetCode] Subsets I (78) & II (90) 解题思路,即全组合算法

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

  5. &lt;LeetCode OJ&gt; 78 / 90 Subsets (I / II)

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

  6. LeetCode(78) Subsets

    题目 Given a set of distinct integers, nums, return all possible subsets. Note: Elements in a subset m ...

  7. (LeetCode 78)SubSets

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

  8. [LeetCode] Subsets 子集合

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

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

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

随机推荐

  1. flask总结之session,websocket,上下文管理

    1.关于session flask是带有session的,它加密后存储在用户浏览器的cookie中,可以通过app.seesion_interface源码查看 from flask import Fl ...

  2. CF1066D Boxes Packing(二分答案)

    题意描述: 你有$n$个物品,每个物品大小为$a_i$,$m$个盒子,每个盒子的容积为$k$.$Maksim$先生想把物品装入盒子中.对于每个物品,如果能被放入当前的盒子中,则放入当前盒子,否则换一个 ...

  3. centos7 使用指定邮箱发送邮件

    一.安装sendmail与mail .安装sendmail: ) centos下可以安装命令:yum -y install sendmail ) 安装完后启动sendmail命令:service se ...

  4. 解决IDEA右键 new 没有新建class/Interface等等选项

    1.File->Project Structure 2.选择Modules-->右边Sources中选择所需目录 然后点击 Sources-->Apply-->OK 3.再在左 ...

  5. 【LAMP整合Redis键值缓存为库分担压力】

    LAMP+ redis 架构图: 安装phpredis扩展 Php主配置文件引入redis库文件 Redis扩展 // 对httpd php扩展连接指定redis服务器

  6. button onclick实现跳转的常用方法

    1.onclick="javascript:window.location.href='aa.htm' " 2.onclick="location='URL' " ...

  7. Order Helper

    using System; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Query; using Microsoft.Crm.Sdk.Messag ...

  8. python学习笔记:第6天 小数据池和编码转换

    目录 1. id 和 == 2. 小数据池 3. 编码和解码 1. id 和 == id:id是一个内置的函数,可以查看变量存放的内存地址(实际上不是真正的物理地址,这里暂时这样理解),用于判断是变量 ...

  9. BugkuWeb本地包含

    知识点:$_REQUEST不是一个函数,它是一个超全局变量,里面包括有$_GET $_POST $_COOKIE的值,$_REPUEST 是接收了 $_GET $_POST $_COOKIE 三个的集 ...

  10. python matplotlibmat 包mplot3d工具 三维视图透视取消

    https://stackoverflow.com/questions/23840756/how-to-disable-perspective-in-mplot3d 简单的解决方法是 ax = fig ...