From fc8dd0cf5f22df167fab4f985e80f9d72eae3492 Mon Sep 17 00:00:00 2001 From: yuanguangxin <274841922@qq.com> Date: Mon, 8 Jun 2020 12:24:18 +0800 Subject: [PATCH] add q78 --- .idea/workspace.xml | 118 ++++++++++++---------- README.md | 1 + src/数组操作/q78_子集/Solution.java | 24 +++++ 3 files changed, 91 insertions(+), 52 deletions(-) create mode 100644 src/数组操作/q78_子集/Solution.java 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; + } +}