SubsetsTotal Accepted:49746Total Submissions:176257My Submissions
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的更多相关文章
- 【leetcode】Word Ladder
Word Ladder Total Accepted: 24823 Total Submissions: 135014My Submissions Given two words (start and ...
- 【leetcode】Unique Paths II
Unique Paths II Total Accepted: 22828 Total Submissions: 81414My Submissions Follow up for "Uni ...
- LeetCode: Unique Paths II 解题报告
Unique Paths II Total Accepted: 31019 Total Submissions: 110866My Submissions Question Solution Fol ...
- LeetCode: Remove Nth Node From End of List 解题报告
Remove Nth Node From End of List Total Accepted: 46720 Total Submissions: 168596My Submissions Quest ...
- Ural 1741 Communication Fiend(隐式图+虚拟节点最短路)
1741. Communication Fiend Time limit: 1.0 second Memory limit: 64 MB Kolya has returned from a summe ...
- leetcode2:Add Two Numbers
Add Two Numbers Total Accepted: 55216 Total Submissions: 249950My Submissions You are given two link ...
- leetcode刷题笔记
(1)Best Time to Buy and Sell Stock Total Accepted: 10430 Total Submissions: 33800My Submissions Say ...
- leetcode__Convert Sorted List to Binary Search Tree
Convert Sorted List to Binary Search Tree Total Accepted: 12283 Total Submissions: 45910My Submissio ...
- leetcode-WordLadder
Word Ladder Total Accepted: 10243 Total Submissions: 58160My Submissions Given two words (start and ...
随机推荐
- Linux设置服务自启动(转载)
From:http://www.cnblogs.com/nerxious/archive/2013/01/18/2866548.html 有时候我们需要Linux系统在开机的时候自动加载某些脚本或系统 ...
- winform窗体的关闭与资源的释放
单纯的this.Dispose(); this.Close();有时候并不能释放出所用资源.因为Dispose()方法,虽然能释放当前窗体的资源,却不能强制结束循环, 要想强制突出当前程序要用:Sy ...
- tomcat服务器不输出访问日志
有时候一个WEB服务作为接口部署在tomcat下,因为访问很频繁,导致/var/log/tomcat7下的访问日志急剧膨胀,影响服务器的性能. 在这里我的方法是关闭访问日志,关闭方法为将访问日志的输出 ...
- Windows和Linux环境下Memcached安装与配置(转)
一.memcached安装配置 windows平台安装 1.memcached-1.2.6-win32-bin.zip下载地址: http://code.jellycan.com/memcached/ ...
- [Flex] ButtonBar系列——控制ButtonBar菜单是否可用
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="ht ...
- EasyUI-datagrid-自动合并单元格(转)
1.目标 1.1表格初始化完成后,已经自动合并好需要合并的行: 1.2当点击字段排序后,重新进行合并: 2.实现 2.1 引入插件 /** * author ____′↘夏悸 * create dat ...
- [SQL]不知道1
表结构,companyid是公司名,productid是产品号,说明每个公司生产多少种产品. companyid productid A A B B B C D D D 要求:取出所有生产的产品包含公 ...
- (转)C#操作PPT
原文地址:http://blog.163.com/loveyingchun_1314/blog/static/2382425120124312627530/ 引用Microsoft.Office.Co ...
- Oracle 删除数据后释放数据文件所占磁盘空间
测试的时候向数据库中插入了大量的数据,测试完成后删除了测试用户以及其全部数据,但是数据文件却没有缩小.经查阅资料之后发现这是 Oracle “高水位”所致,那么怎么把这些数据文件的大小降下来呢?解决办 ...
- php文件删除unlink()详解
请记住从PHP文件创建的教训,我们创建了一个文件,名为testFile.txt . $myFile = "testFile.txt"; $fh = fopen($myFile, ' ...