deno.land / x / masx200_leetcode_test@10.6.5 / combination-sum / 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
26
27
28
29
30
31
32
33
34
35
export default function combinationSum( candidates: number[], target: number,): number[][] { candidates.sort((a, b) => -b + a); const ans: number[][] = []; dfs(candidates, target, [], (path: number[]) => ans.push(path)); return ans;}
function dfs( candidates: number[], target: number, path: number[], output: (path: number[]) => void,) { if (target === 0) { output(path); return; }
for (const [index, can] of candidates.entries()) { if (target >= can) { dfs( index ? candidates.slice(index) : candidates, target - can, [...path, can], output, ); } else { return; } }}
masx200_leetcode_test

Version Info

Tagged at
a year ago