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. Ubuntu配置网络命令(转载)

    From:http://blog.csdn.net/ithomer/article/details/6264881 以eth0为例   1. 以DHCP方式配置网卡 编辑文件: /etc/networ ...

  2. linux下修改path变量(转载)

    比如要把/etc/apache/bin目录添加到PATH中 1.#PATH=$PATH:/etc/apache/bin 使用这种方法,每当登出PATH就会恢复 2.#vi /etc/profile 在 ...

  3. http头信息

    请求头:用于告诉服务器,客户机支持的数据类型accept-charset:用于告诉服务器,客户机采用的编码accept-Encoding:用于告诉服务器,客户机支持的数据压缩格式Host:客户机通过这 ...

  4. Html5中的跨页面消息传输

    1.如果要接受从其他的窗口那里发过来的消息,就必须对窗口对象的message事件进行监控. window.addEventListener("message",function() ...

  5. sql 2008 r2

    http://jingyan.baidu.com/article/6c67b1d6ca06f02787bb1ed1.html

  6. python连mysql时避免出现乱码

    使用python连mysql时候,常常出现乱码,采取以下措施可以避免 1 Python文件设置编码 utf-8 (文件前面加上 #encoding=utf-8)2 MySQL数据库charset=ut ...

  7. Appnium安装——Mac篇

    mac下搭建appium环境有两种方法: 1.直接下载appium.dmg 运行即可 2.使用node从命令行运行appium Mac下的appnium环境搭建 一.首先安装homebrew 1.首先 ...

  8. IIS发布,图片和样式显示不了的问题

    今天本地IIS部署在visual stuio 2013里运行成功的一个项目时,出现了样式和图片显示不了的情况,如下图 所有页面的样式和图片不显示,刚开始以为是发布之后的图片和样式的文件夹没有权限,可是 ...

  9. 慕课网-安卓工程师初养成-2-6 Java中的数据类型

    来源:http://www.imooc.com/code/1230 通常情况下,为了方便物品的存储,我们会规定每个盒子可以存放的物品种类,就好比在“放臭袜子的盒子”里我们是不会放“面包”的!同理,变量 ...

  10. 不能读取文件“itunes.library.itl”因为它是由更高级别的itunes所创建的

    转自:https://zhidao.baidu.com/question/80796363.html 是因为你安装过高版本的后又装你版本的itunes. 你在电脑上搜索所有硬盘上的itunes lib ...