首页 > 其他分享 >LeetCode 90. Subsets II

LeetCode 90. Subsets II

时间:2022-10-18 14:06:32浏览次数:77  
标签:nums res back II vector ans fun 90 LeetCode

​题目​

dfs

class Solution {
public:
vector<vector<int>> ans;
vector<int> res;
vector<vector<int>> subsetsWithDup(vector<int>& nums) {

sort(nums.begin(),nums.end());

fun(nums,0);

return ans;

}

void fun(vector<int>& nums,int x)
{
ans.push_back(res);
for(int i=x;i<nums.size();i++)
{
if(i!=x&&nums[i]==nums[i-1])
{
continue;
}

res.push_back(nums[i]);
fun(nums,i+1);
res.pop_back();
}
}
};



标签:nums,res,back,II,vector,ans,fun,90,LeetCode
From: https://blog.51cto.com/u_15834522/5766267

相关文章

  • LeetCode 87. Scramble String
    ​​题目​​一开始我读错了题意,以为是二分,结果却是动态规划的区间DP我都状态数组是dp[i1][j1][i2][j2],表示第一个字符串的i1到j1区间和第二个字符串的i2到j2区间,是符合条件......
  • LeetCode 88 Merge Sorted Array
    ​​题目​​classSolution{public:voidmerge(vector<int>&nums1,intm,vector<int>&nums2,intn){vector<int>nums3;intk......
  • LeetCode 86. Partition List
    ​​题目​​操作指针的题目/***Definitionforsingly-linkedlist.*structListNode{*intval;*ListNode*next;*ListNode(intx):val(x),next......
  • LeetCode 35 Search Insert Position
    ​​题目​​classSolution{public:intsearchInsert(vector<int>&nums,inttarget){intstart=0;intend=nums.size()-1;......
  • LeetCode 71. Simplify Path
    ​​题目​​字符串问题classSolution{public:stringsimplifyPath(stringpath){stringpaths[10005];intpos=0;paths[0]="/";......
  • LeetCode 34. Find First and Last Position of Element in Sorted Array
    ​​题目​​二分练习classSolution{public:vector<int>searchRange(vector<int>&nums,inttarget){vector<int>ans;if(nums.size()==......
  • LeetCode 76. Minimum Window Substring
    ​​题目​​从第一个字符串中找到最小的子串,让子串中包含第二个字符串中的每一个字符。我的思路来自滑动窗口思想,之前用来做自动摘要的。把第一个字符串中的在第二个字符串......
  • LeetCode 36. Valid Sudoku
    ​​题目​​classSolution{public:inttag[10];boolisValidSudoku(vector<vector<char>>&board){for(inti=0;i<9;i++){......
  • LeetCode 54. Spiral Matrix
    ​​题目​​水题classSolution{public:vector<int>spiralOrder(vector<vector<int>>&matrix){inti=0,j=0;vector<int>ans;int......
  • LeetCode 33 Search in Rotated Sorted Array
    ​​题目​​c++二分classSolution{public:intsearch(vector<int>&nums,inttarget){if(nums.size()==0)return-1;intsta......