Given a set of distinct integers, nums, return all possible subsets.
Note: The solution set must not contain duplicate subsets.
For example,
If nums = [1,2,3]
, a solution is:
[ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], [] ]
排名 93% 哇哈哈哈
/**
* @param {number[]} nums* @return {number[][]}
*/
var subsets = function(nums) {
arr_l=[[]];
n=nums.length;
arr=[];
for(i=1;i<=nums.length;i++){
search(nums,i);
}
function search(nums1,i){
if(i==1){
for(var j=0;j<nums1.length;j++){
//push number to arr
// push arr to arr_l
// pop the arr laster number;
arr.push(nums1[j]);
arr_l.push(arr.slice());
arr.pop();
}
return;
}
for(j=0;j<nums1.length-1;j++){
arr.push(nums1[j]);
search(nums1.slice(j+1),i-1);
arr.pop();
}
}
return arr_l;
};