1
black 2020-03-03 12:10:04 +08:00
回溯算法
|
2
ASpiral 2020-03-03 12:13:57 +08:00
|
3
zjbztianya 2020-03-03 12:20:15 +08:00
for mask = 1, 2^n-1 ,把 mask 看成二进制,如果对应位是1,那么把对应的数组的数字取出来....不过用 dfs 也行,要么取,要么不取
|
4
rabbbit 2020-03-03 12:32:16 +08:00 1
function coll(list) {
const result = []; list.forEach(num => { for (let j = 0, len = result.length; j < len; j++) { result.push(num + result[j]); } result.push(num); }); return result; } |