✔️ 100% Fastest Swift Solution
\nclass Solution {\n    func subsetsWithDup(_ nums: [Int]) -> [[Int]] {\n        var ans = Set<[Int]>()\n        var comb = [Int]()\n        \n        subset(nu
```\nclass Solution {\n    func subsetsWithDup(_ nums: [Int]) -> [[Int]] {\n        var ans = Set<[Int]>()\n        var comb = [Int]()\n        \n        subset(nums.sorted(), 0, &comb, &ans)\n        return Array(ans)\n    }\n    \n    \n    func subset(_ nums: [Int], _ index: Int, _ comb: inout [Int], _ ans: inout Set<[Int]>) {\n        if index >= nums.count {\n            ans.insert(comb)\n            \n        } else {\n            subset(nums, index+1, &comb, &ans)\n            \n            comb.append(nums[index])\n            subset(nums, index+1, &comb, &ans)\n            comb.removeLast()\n        }\n    }\n    \n}\n```\n\nLet me know in comments if you have any doubts. I will be happy to answer.\n\nPlease upvote if you found the solution useful.
['Swift']