(1)先假设数列的元素不重复,例如[ 4, 2 ,3 ],可知总共有2^3=8个子集,在加一个空集;
(2)对数列排序,可方便生成子集升序[2, 3 , 4];
(3)每个子集对应一个二进制值,0-空集 1-> (2) 2->(3) 3->(2,3) …… 7->(2,3,4),二进制数1的位置对应数列中相应位置的数。遍历一遍可得结果。
(4)进一步,如果数列有重复怎么办?例如[ 2 , 3...
分类:
其他好文 时间:
2014-12-04 20:05:02
阅读次数:
124
Subsets IIGiven a collection of integers that might contain duplicates,S, return all possible subsets.Note:Elements in a subset must be in non-descend...
分类:
其他好文 时间:
2014-12-04 19:32:41
阅读次数:
163
Given a collection of integers that might contain duplicates,S, return all possible subsets.Note:Elements in a subset must be in non-descending order....
分类:
其他好文 时间:
2014-12-03 22:47:54
阅读次数:
153
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 co...
分类:
其他好文 时间:
2014-11-23 17:25:14
阅读次数:
198
给定一个数组,返回所有的非重复的可能。例如给定IfS=[1,2,2], a solution is:[ [2], [1], [1,2,2], [2,2], [1,2], [] ]其实这题类似的有Combination和Subsets。有兴趣的可以看看之前的解题方法。那大概是第70题左右,十天以前做的...
分类:
其他好文 时间:
2014-11-23 15:43:49
阅读次数:
145
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 exa...
分类:
其他好文 时间:
2014-11-23 14:34:54
阅读次数:
158
Given a collection of integers that might contain duplicates,S, return all possible subsets.Note:Elements in a subset must be in non-descending order....
分类:
其他好文 时间:
2014-11-23 12:56:59
阅读次数:
179
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 co...
分类:
其他好文 时间:
2014-11-23 11:42:48
阅读次数:
233
Given a collection of integers that might contain duplicates,S, return all possible subsets.Note:Elements in a subset must be in non-descending order....
分类:
其他好文 时间:
2014-11-21 14:03:57
阅读次数:
160
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 co...
分类:
其他好文 时间:
2014-11-21 01:17:47
阅读次数:
293