78[LeetCode] Subsets
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的更多相关文章
- LeetCode:Subsets I II
求集合的所有子集问题 LeetCode:Subsets Given a set of distinct integers, S, return all possible subsets. Note: ...
- LeetCode Subsets II (DFS)
题意: 给一个集合,有n个可能相同的元素,求出所有的子集(包括空集,但是不能重复). 思路: 看这个就差不多了.LEETCODE SUBSETS (DFS) class Solution { publ ...
- LeetCode 78. 子集(Subsets) 34
78. 子集 78. Subsets 题目描述 给定一组不含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集). 说明: 解集不能包含重复的子集. 每日一算法2019/6/6Day 34L ...
- [LeetCode] Subsets I (78) & II (90) 解题思路,即全组合算法
78. Subsets Given a set of distinct integers, nums, return all possible subsets. Note: Elements in a ...
- <LeetCode OJ> 78 / 90 Subsets (I / II)
Given a set of distinct integers, nums, return all possible subsets. Note: Elements in a subset must ...
- LeetCode(78) Subsets
题目 Given a set of distinct integers, nums, return all possible subsets. Note: Elements in a subset m ...
- (LeetCode 78)SubSets
Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset must be ...
- [LeetCode] Subsets 子集合
Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset must be ...
- [LeetCode] Subsets II 子集合之二
Given a collection of integers that might contain duplicates, S, return all possible subsets. Note: ...
随机推荐
- Google Performance工具,你还不会用?Git走起。
2018俄罗斯世界杯如火如荼的进行中,第一轮各种冷门,让大家的确大跌眼界,尤其是那些买球的同志们,慌得一笔,还敢继续买吗?话说来,看球归看球,学习还是不能落下,我们来学习Chrome Devtool ...
- Swift_闭包
Swift_闭包 点击查看源码 闭包优化 //闭包优化 func testClosures() { //函数做参数 排序 let names = ["XuBaoAiChiYu", ...
- c和c++单链表
c++版 #include<iostream> #include<malloc.h> using namespace std; struct node{ int data; n ...
- shutil.rmtree()
shutil.rmtree(path, ignore_errors=False, onerror=None) #递归地删除文件 def rmtree(path, ignore_errors=Fal ...
- python名称空间介绍
python名称空间介绍 名称空间 python 中名称空间分三种: 内置名称空间 全局名称空间 局部名称空间 内置名称空间: 原码里面的一些函数都是存在这个内存空间中,任何模块均可访问它,它存放着内 ...
- 纯JS实现轮播图特效——详解
<div id="slider"> <div id="sliderImgs"> <img src="img/mi04.j ...
- css中三种隐藏方式
1.overflow 溢出隐藏 overflow:hidden 2.display 隐藏不占据原来的文档,即会让出空间 display:black 显示 display:none 隐藏 3.vis ...
- Apache httpd Server Notes
1. httpd启动.停止以及重启 启动: apachectl –f $PATH_TO_CONF/httpd.conf 停止及重启 apachectl –k stop/restart/graceful ...
- yii学习笔记(4),获取请求数据的request组件
yii在控制器中获取请求数据需要通过request组件来完成 <?php namespace app\controllers; use yii; use yii\web\Controller; ...
- mysql 库和表占用空间查询
1. 查看该数据库实例下所有库大小,得到的结果是以MB为单位 as sum from information_schema.tables; 2.查看该实例下各个库大小 as total_mb, as ...