用C++的STL的set可以解决子集问题吗?
就是找到所有的子集
2条回答 默认 最新
烟雨龙升 2022-08-08 16:05关注不知道你需要的是不是这种
vector<vector<int>> subsetsWithDup(vector<int>& nums) { sort(nums.begin(),nums.end()); set<vector<int>> se; for(auto x : nums) { set<vector<int>> temp; for(auto c : se) { auto k = c; k.push_back(x); temp.insert(k); } temp.insert({x}); se.insert(temp.begin(),temp.end()); } vector<vector<int>> ve; ve.push_back({}); for(auto c : se) { ve.push_back(c); } return ve; }评论 打赏 举报解决 1无用