diff --git a/.idea/workspace.xml b/.idea/workspace.xml index df9bbec..f573a25 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,8 +2,9 @@ + - + - + + + - - - - - - - + + + @@ -263,14 +258,11 @@ - - - - 1581705262462 - 1581705659513 @@ -608,7 +600,14 @@ - @@ -693,54 +692,69 @@ - + - + - - - + + + - - + + + + - - + + + + - - + + + + - - + + + - - + + + + - - + + + + - - + + + + + + @@ -749,11 +763,11 @@ - + - + diff --git a/README.md b/README.md index cbc5038..6cea521 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ * [q54_螺旋矩阵](/src/数组操作/q54_螺旋矩阵) * [q73_矩阵置零](/src/数组操作/q73_矩阵置零) +* [q78_子集](/src/数组操作/q78_子集) * [q945_使数组唯一的最小增量](/src/数组操作/q945_使数组唯一的最小增量) ### 栈相关 diff --git a/src/数组操作/q78_子集/Solution.java b/src/数组操作/q78_子集/Solution.java new file mode 100644 index 0000000..d47219e --- /dev/null +++ b/src/数组操作/q78_子集/Solution.java @@ -0,0 +1,24 @@ +package 数组操作.q78_子集; + +import java.util.ArrayList; +import java.util.List; + +/** + * 向子集中添加子集合 o(n*2^n) + */ +public class Solution { + + public List> subsets(int[] nums) { + List> result = new ArrayList<>(); + result.add(new ArrayList<>()); + for (int i = 0; i < nums.length; i++) { + int size = result.size(); + for (int j = 0; j < size; j++) { + List temp = new ArrayList<>(result.get(j)); + temp.add(nums[i]); + result.add(temp); + } + } + return result; + } +}