Created
July 16, 2022 20:59
-
-
Save D-Lite/3992559393305955da959397233c8136 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {number[]} nums | |
* @return {number[][]} | |
*/ | |
var subsets = function(nums) { | |
if(nums.length < 2) return nums | |
let result = [] | |
function recurse(i, temp) { | |
if(i === nums.length ) { | |
result.push(temp) | |
return | |
} | |
// array[i] | |
recurse(i + 1, [nums[i], ...temp]) | |
recurse(i+1, temp) | |
} | |
recurse(0, []) | |
return result | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment