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. bootstrap-导航、选项卡

    导航: <!-- nav 导航的基础样式 --> <div class="container"> <div class="row" ...

  2. clone代码

    例子1:

  3. SPCOMM 接收数据不完整!该如何解决

    SPCOMM 接收数据不完整!该如何解决   SPCOMM 接收数据不完整!我作了一个 读取地磅数据的程序,是用spcomm接收的! 总共有五台地磅,其他4台地磅数据读取都正常.但是有一台接收数据的时 ...

  4. [Excel]C#操作Excel(导入导出)

    /// <summary> /// 读取Excel文档 /// </summary> /// <param name="Path">文件名称&l ...

  5. [datatable]两个DataTable 连接

    using System; using System.Collections.Generic; using System.Text; using System.Data; namespace Cons ...

  6. GridControl 继承写法修改自己的GridControl

    namespace GridControlDemo { class MyGridControl : GridControl { protected override BaseView CreateDe ...

  7. HDU 5808[数位dp]

    /* 题意: 给你l和r,范围9e18,求l到r闭区间有多少个数字满足,连续的奇数的个数都为偶数,连续的偶数的个数都为奇数. 例如33433符合要求,44不符合要求.不能含有前导零. 思路: 队友说是 ...

  8. tarjan 边双连通分量 对点进行分组 每组点都在一个双连通分量里边

    int dfn[N],low[N],id[N],s[N],p,num,t,son[N];//dfn记录dfs时间戳//low代表当前点到达的最小时间戳,id对点进行分组编号.num是时间戳//s临时存 ...

  9. 【转载】s3c2440裸机开发调试环境(MDK4.6,Jlink v8,mini2440)

    用于arm裸机程序开发的IDE基本有 以下3个:MDK,IAR,还有ADS.具体它们的具体情况在这里我就不多说了,百度一下就明白了.由于之前开发c51,stm32时候都使用了MDK开发环境,而且MDK ...

  10. java使用jacob将office转pdf

    1.此处代码是把office文档转换成pdf的工具类,在BS架构的产品中,我们可以使用基于JS的pdf插件显示pdf文档,但是前提IE需要按照adobe的pdf软件,对于非IE不用安装.2.可以基于f ...