Last active
January 29, 2022 12:21
-
-
Save anil477/f780e97aaf7dd7ea6d9b041da5e14388 to your computer and use it in GitHub Desktop.
78. Subsets
This file contains 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
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