class Solution {
public:
vector<vector<int>> subsets(vector<int>& nums) {
sort(nums.rbegin(),nums.rend());
int n=nums.size();
vector<vector<int>>res;
for(int i=0;i<pow(2,n);i++){
vector<int> cur;
int k=n,j=i;
do{
if(j%2){
cur.push_back(nums[k-1]);
}
j/=2;
}while(--k);
res.push_back(cur);
}
return res;
}
};
LeetCode - 78 Subsets
最新推荐文章于 2024-07-22 16:55:07 发布