Given a set of distinct integers, nums, return all possible subsets (the power set).

Note: The solution set must not contain duplicate subsets.

Example:

Input: nums = [1,2,3]
Output:
[
[3],
  [1],
  [2],
  [1,2,3],
  [1,3],
  [2,3],
  [1,2],
  []
]
 class Solution {

     List<List<Integer>> res = new ArrayList<>();

     public List<List<Integer>> subsets(int[] nums) {
Arrays.sort(nums);
help(new ArrayList<>(), nums, 0);
return res;
}
private void help(List<Integer> temp,int[] nums,int index){
temp = new ArrayList<>(temp);
res.add(temp);
for(int i= index;i<nums.length;i++){
temp.add(nums[i]);
help(temp,nums,i+1);
temp.remove(temp.size()-1);
}
}
}

78. Subsets(回溯)的更多相关文章

  1. 78. Subsets(M) & 90. Subsets II(M) & 131. Palindrome Partitioning

    78. Subsets Given a set of distinct integers, nums, return all possible subsets. Note: The solution ...

  2. leetcode 78. Subsets 、90. Subsets II

    第一题是输入数组的数值不相同,第二题是输入数组的数值有相同的值,第二题在第一题的基础上需要过滤掉那些相同的数值. level代表的是需要进行选择的数值的位置. 78. Subsets 错误解法: cl ...

  3. 刷题78. Subsets

    一.题目说明 题目78. Subsets,给一列整数,求所有可能的子集.题目难度是Medium! 二.我的解答 这个题目,前面做过一个类似的,相当于求闭包: 刷题22. Generate Parent ...

  4. 78. Subsets C++回溯法

    本题还是基本的回溯法.就是回溯函数的参数选择上要花点心思! class Solution { public: void backTrack(vector<int> ans, vector& ...

  5. LeetCode OJ 78. Subsets

    Given a set of distinct integers, nums, return all possible subsets. Note: Elements in a subset must ...

  6. subsets 回溯 给定集合,枚举子集。元素不重复

    这个回溯感觉掌握的有些熟练了. 两种方式,递归和循环. 感觉就是套框架了. /** * Return an array of arrays of size *returnSize. * The siz ...

  7. LeetCode 78 Subsets (所有子集)

    题目链接:https://leetcode.com/problems/subsets/#/description   给出一个数组,数组中的元素各不相同,找到该集合的所有子集(包括空集和本身) 举例说 ...

  8. 78. Subsets (Back-Track, DP)

    Given a set of distinct integers, nums, return all possible subsets. Note: Elements in a subset must ...

  9. [LeetCode] 78. Subsets 子集合

    Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset must be ...

随机推荐

  1. 导入google地图

    一直报地图页面的 java.lang.incompatibleclasschangeerror 想来想去,应该是包不兼容的原因,原本以为,在 build.gradle 里面 compileSdkVer ...

  2. mongodb3.2系统性学习——3、update()操作

     mongodb 包含众多的原子性操作: 实例: //连接数据库 dbService = connect("localhost:27017"); //选择插入集合 db = dbS ...

  3. JS-检测浏览器类型及版本

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  4. FZU 2082(过路费)

    题目链接:传送门 题目大意:中文题,略 题目思路:树链剖分(注意要把边上的权值转移到深度较大的点上来维护) 最后当top[x]==top[y]注意id[x]+1因为是维护的点而题目是边 如果不+可能会 ...

  5. JSP自定义标签开发入门《转》

    JSP自定义标签开发入门 一般情况下开发jsp自定义标签需要引用以下两个包 import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; ...

  6. 第k最短路A*启发式搜索

    Remmarguts' Date Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 21549   Accepted: 5862 ...

  7. Oracle命令(三):Oracle用户

    1.显示当前用户名 select user from dual; show user 2.显示当然用户有哪些表 select * from tab; 3.显示当所有用户的表 select * from ...

  8. Visual Studio 2017正式版离线安装方法

    Visual Studio 2017 RTM正式版离线安装及介绍. 首先至官网下载:https://www.visualstudio.com/zh-hans/downloads/ VS 2017 正式 ...

  9. 组织机构代码校验码生成算法(C#版)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  10. 数据字典Data Dict

    数据字典 所有的数据表都属于数据库对象,每当创建一张数据表的时候,会自动在指定的数据字典表执行一个增加语句(这个增加语言我们是不知道的),数据字典的数据操作只能通过命令完成,不能直接使用SQL完成. ...