78. 子集
题目链接
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/subsets/
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
题目描述
题目分析
- 回溯法
子集是树中所有节点。是模板。
无序 ->for从startIndex开始而不是0开始。
长度
0 【】
1 【1】【2】【3】
2 【1,2】【1,3】【2,3】
3 【1,2,3】
每次向下递归的元素都是该元素后面的元素
class Solution {
private:
vector<vector<int>>res;
vector<int> path;
void backtracking(vector<int>& nums, int startIndex){
res.