Given an array of unique integers, return all possible subsets (the power set), in any order, without duplicates.
Every path in the recursion is a subset. Record the current path, then try extending it with each later number.
1function subsets(nums: number[]): number[][] {2const res: number[][] = [], path: number[] = [];3function dfs(start: number) {4res.push([...path]);5for (let i = start; i < nums.length; i++) {6path.push(nums[i]);7dfs(i + 1);8path.pop();9}10}11dfs(0);12return res;13}
Record [].
Space: play/pause · ←/→: step