专业h5网站制作,企业管理专业就业方向,专业开发app公司,网站内容建设出现的问题原题链接
一. 题目描述
给你一个整数数组 nums #xff0c;数组中的元素 互不相同 。返回该数组所有可能的
子集
#xff08;幂集#xff09;。
解集 不能 包含重复的子集。你可以按 任意顺序 返回解集。 示例 1#xff1a;
输入#xff1a;nums [1,2,3]
输出…原题链接
一. 题目描述
给你一个整数数组 nums 数组中的元素 互不相同 。返回该数组所有可能的
子集
幂集。
解集 不能 包含重复的子集。你可以按 任意顺序 返回解集。 示例 1
输入nums [1,2,3]
输出[[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]示例 2
输入nums [0]
输出[[],[0]]提示
1 nums.length 10-10 nums[i] 10nums 中的所有元素 互不相同
二. 解题思路
这个题就十分简单了相信大家一定可以自行解决不做解答。
话不多说上代码
三. 代码
class Solution {
public:vectorvectorint res;vectorint path;void back(vectorint nums, int startindex){if(startindex nums.size()) return;for(int i startindex; i nums.size(); i){path.push_back(nums[i]);res.push_back(path);back(nums, i 1);path.pop_back();}}vectorvectorint subsets(vectorint nums) {res.push_back(path);back(nums, 0);return res;}
};
四. 总结
时间复杂度
空间复杂度
喜欢的话给个关注吧