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 ...
随机推荐
- vim扩展配置
在用户根目录下新建 “.vimrc”文件,键入一下代码: set syntax=on "高亮语法 set fenc=utf- "设定默认解码 set fencs=utf-,usc- ...
- 新建的表如果还没有数据,用exp导的时候会忽略
源地址:http://www.07net01.com/2015/07/884873.html
- 认识与学习BASH
应用程序在最外面,就如同鸡蛋的外壳一样,因此被称呼为shell(壳程序).其实壳程序的功能只是提供操作系统的一个接口. 应用程序 ↓ 操作系统(系统呼叫+核心) ↓ 硬件 linux预设的shell就 ...
- 什么时候用position
postion的情况有很多,fixed是固定,在我们需要把元素固定在某一个位置时使用 absolute和relative要配合使用,要把一个元素固定在另一个元素内某个位置时使用,外部元素为relati ...
- Collection集合List、Set
Collection集合,用来保存一组数据的数据结构. Collection是一个接口,定义了所有集合都应该包含的特征和行为 Collection派生出了两类集合 List和Set List接口:Li ...
- FreeMarker语法知识
FreeMarker的模板文件并不比HTML页面复杂多少,FreeMarker模板文件主要由如下4个部分组成:1,文本:直接输出的部分2,注释:<#-- ... -->格式部分,不会输出3 ...
- SpringMVC 注解事务
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactio ...
- Oracle 删除数据后释放数据文件所占磁盘空间
测试的时候向数据库中插入了大量的数据,测试完成后删除了测试用户以及其全部数据,但是数据文件却没有缩小.经查阅资料之后发现这是 Oracle “高水位”所致,那么怎么把这些数据文件的大小降下来呢?解决办 ...
- PHP截取IE浏览器并缩小原图的方法
这篇文章主要介绍了PHP截取IE浏览器并缩小原图的方法,涉及PHP调用com组件实现图像截取的相关技巧,需要的朋友可以参考下 本文实例讲述了PHP截取IE浏览器并缩小原图的方法.分享给大家供大家参考, ...
- <iOS>other linker flags[转]
包含静态库时候需要在Target的Other linker flags里面加上值:-objC,-all_load,-force_load 对于64位机子和iPhone OS应用 解决方法是使用-all ...