Skip to content

Instantly share code, notes, and snippets.

@anil477
Last active January 29, 2022 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anil477/f780e97aaf7dd7ea6d9b041da5e14388 to your computer and use it in GitHub Desktop.
Save anil477/f780e97aaf7dd7ea6d9b041da5e14388 to your computer and use it in GitHub Desktop.
78. Subsets
class Solution {
// 78. Subsets
// https://leetcode.com/problems/subsets/
public List<List<Integer>> subsets(int[] nums) {
List<List<Integer>> output = new LinkedList();
rec(nums, output, new ArrayList<>(), 0);
// Arrays.sort(nums);
return output;
}
public void rec(int[] input, List<List<Integer>> output, List<Integer> temp, int index) {
output.add(new ArrayList<>(temp));
for (int i = index; i < input.length; i++) {
temp.add(input[i]);
rec(input, output, temp, i+1);
temp.remove(temp.size() - 1);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment