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.
题目要求 :
求整数数组的所有子集
注意:
1、子集元素按非降序排列
2、不包含重复的子集
解题思路:
求解这类诸如子集的题目,都可以采用回溯法。(剪枝+递归)
代码如下:
class Solution {private: vector> ans;public: void collectSubSet(vector &S,vector x,int len,int idx){ if(idx==len){ vector subset; for(int i=0;i