[LeetCode] Subsets (bfs的vector实现)
Given a set of distinct integers, S, return all possible subsets.
Note:
- Elements in a subset must be in non-descending order.
- The solution set must not contain duplicate subsets.
For example, If S = [1,2,3]
, a solution is:
- [
- [3],
- [1],
- [2],
- [1,2,3],
- [1,3],
- [2,3],
- [1,2],
- []
- ]
- class Solution {
- public:
- vector<vector<int> > subsets(vector<int> &S) {
- vector<vector<int> > res;
- int len = S.size();
- vector<int> temp0,temp;
- res.push_back(temp);
- int start = ,end = ;
- while(start < end)
- {
- temp = res[start];
- temp0 = temp;
- start++;
- int n = ;
- for(int i=;i<len;i++){
- if(find(temp.begin(),temp.end(),S[i])==temp.end()){
- temp.push_back(S[i]);
- sort(temp.begin(),temp.end());
- if(find(res.begin(),res.end(),temp)==res.end()){
- res.push_back(temp);
- n++;
- }
- temp = temp0;
- }//end if
- }//end for
- end += n;
- }//end while
- return res;
- }//end func
- };
[LeetCode] Subsets (bfs的vector实现)的更多相关文章
- 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] Subsets II 子集合之二
Given a collection of integers that might contain duplicates, S, return all possible subsets. Note: ...
- [LeetCode] Subsets 子集合
Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset must be ...
- LeetCode Subsets (DFS)
题意: 给一个集合,有n个互不相同的元素,求出所有的子集(包括空集,但是不能重复). 思路: DFS方法:由于集合中的元素是不可能出现相同的,所以不用解决相同的元素而导致重复统计. class Sol ...
- 【LeetCode】BFS(共43题)
[101]Symmetric Tree 判断一棵树是不是对称. 题解:直接递归判断了,感觉和bfs没有什么强联系,当然如果你一定要用queue改写的话,勉强也能算bfs. // 这个题目的重点是 比较 ...
- [LeetCode] Combinations (bfs bad、dfs 递归 accept)
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For exampl ...
- [LeetCode] Subsets I (78) & II (90) 解题思路,即全组合算法
78. Subsets Given a set of distinct integers, nums, return all possible subsets. Note: Elements in a ...
- Leetcode: Subsets & SubsetsII
Subsets Description: Given a set of distinct integers, S, return all possible subsets. Note: Element ...
随机推荐
- POJ 1743 (后缀数组+不重叠最长重复子串)
题目链接: http://poj.org/problem?id=1743 题目大意:楼教主の男人八题orz.一篇钢琴谱,每个旋律的值都在1~88以内.琴谱的某段会变调,也就是说某段的数可以加减一个旋律 ...
- 搭建你的第一个Django应用程序
首先你要确保你机器上面安装了python:Python开发_python的安装 python的相关学习资料:http://www.cnblogs.com/hongten/tag/python/ 其次, ...
- 地球上最大的PHP站点 后端技术解密
Facebook的扩展性挑战 在我们讨论细节之前,这里有一些Facebook已经做的软件规模: ◆Facebook有570000000000每月页面浏览量 (据Google Ad Planner) ◆ ...
- Leetcode | substr()
求子串当然最经典的就是KMP算法了.brute force算法在leetcode上貌似也有一些技巧. brute force: char* StrStr(const char *str, const ...
- ImageMagick jmagick 安装
在安装ImageMagick之前,请检查下面包已经安装 tiff-3.9.5.tar.gz (rpm -qa|grep libtiff检查是否已经安装) libpng-1.2.46.t ...
- 【翻译】Kinect v2程序设计(C++) Color篇
Kinect SDK v2预览版,获取数据的基本流程的说明.以及取得Color图像的示例程序的介绍. 上一节,是关于当前型号Kinect for Windows(后面称作Kinect v1)和次世代型 ...
- Sublime Text3注册码(可用)
Sublime Text3注册码(可用) (2014-12-20 21:24:56) 转载▼ 标签: sublime sublime3 sublimetext sublimetext3 分类: 实用工 ...
- mysql 将null转代为0
mysql 将null转代为0 分类: Mysql2012-12-15 11:56 6447人阅读 评论(1) 收藏 举报 1.如果为空返回0 select ifnull(null,0) 2.如果为空 ...
- Solr定时更新
今天用到solr定时重建索引和增量更新技术,就从网上搜了一些资料,在这里给大家整理了一下,也经过了自己的测试,没有异常. Solr官方提供了很强大的Data Import Request Handle ...
- w win cmd VS broswer
php -f Fetch data from db , use php without any bugs to analyse the data and read and write db, with ...