Subsets

Total Accepted: 49746 Total Submissions: 176257My Submissions

Given a set of distinct integers, nums, return all possible subsets.

Note:

Elements in a subset must be in non-descending order.

The solution set must not contain duplicate subsets.

For example,

If nums = [1,2,3], a solution is:

[

[3],

[1],

[2],

[1,2,3],

[1,3],

[2,3],

[1,2],

[]

]

package hashmap;

import java.util.ArrayList;
import java.util.Arrays; public class test { public static void main(String[] args) {
// TODO Auto-generated method stub
int[] s={1,2,3};
ArrayList<ArrayList<Integer>> result=subsets(s); for ( int i = 0; i < result.size(); i++){ System.out.println(result.get(i));
}
}
public static void dfs(ArrayList<ArrayList<Integer>> res, ArrayList<Integer> l, int[] s, int pos){
System.out.println("total pos:"+pos);
if(pos == s.length){
res.add(new ArrayList(l));
System.out.println("----------------------");
for ( int i = 0; i < res.size(); i++)
System.out.println("res"+res.get(i));
System.out.println("----------------------");
return ;
} dfs(res, new ArrayList(l), s, pos+1);
l.add(s[pos]);
System.out.println("addelem:"+pos+":"+s[pos]);
System.out.println("dfs infor:"+pos);
dfs(res,l, s, pos+1);
System.out.println("l----------------------");
for ( int k = 0; k < l.size(); k++){ System.out.println(l.get(k));
} System.out.println("l----------------------"); System.out.println("l----------------------");
} public static ArrayList<ArrayList<Integer>> subsets(int[] S) {
ArrayList<ArrayList<Integer>> res = new ArrayList<ArrayList<Integer>>();
ArrayList<Integer> l = new ArrayList<Integer>(); Arrays.sort(S); dfs(res, l, S, 0);
return res;
} }

SubsetsTotal Accepted:49746Total Submissions:176257My Submissions的更多相关文章

  1. 【leetcode】Word Ladder

    Word Ladder Total Accepted: 24823 Total Submissions: 135014My Submissions Given two words (start and ...

  2. 【leetcode】Unique Paths II

    Unique Paths II Total Accepted: 22828 Total Submissions: 81414My Submissions Follow up for "Uni ...

  3. LeetCode: Unique Paths II 解题报告

    Unique Paths II Total Accepted: 31019 Total Submissions: 110866My Submissions Question Solution  Fol ...

  4. LeetCode: Remove Nth Node From End of List 解题报告

    Remove Nth Node From End of List Total Accepted: 46720 Total Submissions: 168596My Submissions Quest ...

  5. Ural 1741 Communication Fiend(隐式图+虚拟节点最短路)

    1741. Communication Fiend Time limit: 1.0 second Memory limit: 64 MB Kolya has returned from a summe ...

  6. leetcode2:Add Two Numbers

    Add Two Numbers Total Accepted: 55216 Total Submissions: 249950My Submissions You are given two link ...

  7. leetcode刷题笔记

    (1)Best Time to Buy and Sell Stock Total Accepted: 10430 Total Submissions: 33800My Submissions Say ...

  8. leetcode__Convert Sorted List to Binary Search Tree

    Convert Sorted List to Binary Search Tree Total Accepted: 12283 Total Submissions: 45910My Submissio ...

  9. leetcode-WordLadder

    Word Ladder Total Accepted: 10243 Total Submissions: 58160My Submissions Given two words (start and  ...

随机推荐

  1. (Delphi) Windows 32 API程序设计目录

    这里所有程序均使用Delphi调用Windows 32 API方式实现,并不是使用VCL已经封装好的类实现的! (一)第一个窗口程序 01 创建第一个窗口.

  2. 【转】group by多个字段理解

    来源:http://uule.iteye.com/blog/1569262 首先group by 的简单说明: group by 一般和聚合函数一起使用才有意义,比如 count sum avg等,使 ...

  3. maven项目导入eclipse

    maven项目的配置文件 web java文件都在src下面 src/main/java src/main/webapp src/main/webapp/web-inf 导入后要重新添加jar包,设置 ...

  4. flexbox弹性盒模型

    div { display:flex; } div a{ }

  5. editplus格式化xml文档

    使用editplus打开xml文档,发现文件内容没有格式化,非常难看,使用IE9打开这个xml文档是格式化的,但是IE9打开不能编辑. 在网上找了一些资料发现能够通过一个小插件来是editplus格式 ...

  6. (easy)LeetCode 225.Implement Stack using Queues

    Implement the following operations of a stack using queues. push(x) -- Push element x onto stack. po ...

  7. springMVC3 ckeditor3.6 图片上传 JS回调

    一.引入js文件 <script type="text/javascript" src="<%=base %>/resources/ckeditor/c ...

  8. 项目管理: Maven 让事情变得简单

    http://maven.apache.org/,  Maven其实就是为java实现的一个构建工具.他比Ant更高端. 目前,绝大多数开发人员都把 Ant 当作 Java 编程项目的标准构建工具.遗 ...

  9. 合并 hdfs 文件

     待研究,只做保存 将HDFS中不同目录下面的数据合在一起,并存放在指定的目录中,示例如: sqoop merge –new-data /test/p1/person –onto /test/p2 ...

  10. Ubuntu Qt arm-linux-androideabi-gcc: Command not found

    :-1: error: /opt/Qt/android-ndk-r9c/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin/arm- ...