比如给出 new int[]{1,2,3}
那么返回
{1,2,3,1+2,1+3,2+3,1+2+3}
元素不能重复使用,但可能给出 new int[]{1,1,2,3} 这样 1+1 也对
谢谢告知
那么返回
{1,2,3,1+2,1+3,2+3,1+2+3}
元素不能重复使用,但可能给出 new int[]{1,1,2,3} 这样 1+1 也对
谢谢告知
1
black Mar 3, 2020
回溯算法
|
2
ASpiral Mar 3, 2020
|
3
zjbztianya Mar 3, 2020
for mask = 1, 2^n-1 ,把 mask 看成二进制,如果对应位是1,那么把对应的数组的数字取出来....不过用 dfs 也行,要么取,要么不取
|
4
rabbbit Mar 3, 2020 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; } |