deno.land / x / masx200_leetcode_test@10.6.5 / subsets-ii / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// const uniqBy=_.uniqByexport default function subsetsWithDup(nums: number[]): number[][] { nums.sort((a, b) => a - b); const ans = []; const set = new Set<string>(); const n = nums.length; for (let mask = 0; mask < 2 ** n; ++mask) { const t = []; for (let i = 0; i < n; ++i) { if (mask & (2 ** i)) { t.push(nums[i]); } }
const str = t.join(","); if (set.has(str)) { continue; } else { ans.push(t); set.add(str); } } return ans;}
masx200_leetcode_test

Version Info

Tagged at
a year ago