-
78. SubsetsAlgorithm/java tip 2021. 3. 7. 00:40
leetcode.com/problems/subsets/
class Solution { List<List<Integer>> ret = new ArrayList<>(); public List<List<Integer>> subsets(int[] nums) { List<Integer> subset = new ArrayList<>(); BT(nums, 0, subset); return ret; } public void BT(int[] nums, int index, List<Integer> subset) { if(index == nums.length) { ret.add(new ArrayList<>(subset)); return; } int c = nums[index]; BT(nums, index + 1, subset); subset.add(c); BT(nums, index + 1, subset); subset.remove(subset.size() - 1); } }
'Algorithm > java tip' 카테고리의 다른 글
530. Minimum Absolute Difference in BST (0) 2021.03.13 589. N-ary Tree Preorder Traversal (0) 2021.03.13 404. Sum of Left Leaves (0) 2021.03.06 22. Generate Parentheses (0) 2021.03.06 559. Maximum Depth of N-ary Tree (0) 2021.03.06