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 ...
随机推荐
- java中使用session的一些细节
获取session的时候会产出一个sessionid并且发给客户端,第二次回发的时候再根据该sessionid获取session.如果cookies被禁用,则需要通过URL传入. asp.net下的s ...
- Excel粘贴到textarea换行符替换
复制到→ Excel列表的内容复制到textarea中后,前台取到的文本是这样的: chrome监视显示 console.log输出 现在需要将excel中的每行数据拼接起来用“;”隔开,方法如下: ...
- TFS如何设置在客户端独占签出
步骤:1.打开源代码管理资源管理器,点击“工作区”的下拉框,选择,“工作区”2.选择编辑3.选择“高级”4.进入编辑工作区,tfs中“位置”选项中,默认的时本地,如果想独占签出,这里我们就必须设置成“ ...
- 九度OJ1061
//C++ sort函数的多重排序 #include <iostream> #include<algorithm> #include<string> using n ...
- [SQL]分布师查询
EXEC sp_addlinkedserver @server='serverA', @srvproduct='', @provider='SQLOLEDB', @datasrc='192.168.0 ...
- Redis链接上不的问题
问题描述: 同样配置的redis及系统环境,在两台服务器(A.B两台服务)上部署,但是其中一台(A),运行一段时间,就链接不上了,从开始运行redis到redis链接不上,这个时间间隔,不一定有时候是 ...
- poj 1789 Truck History 最小生成树
点击打开链接 Truck History Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 15235 Accepted: ...
- Reactor模式与观察者模式
多线程编程常见模式 观察者模式: 单一的观察点,事件单一 反应器模式: 多个观察点,事件不单一(NIO里面的Selector选择器,基于Channel的事件进行多路的IO复用机制) 图-网上都是这张, ...
- Mysql中的count()与sum()区别
首先创建个表说明问题 CREATE TABLE `result` ( `name` varchar(20) default NULL, `subject` varchar(20) default NU ...
- Visual 中控制台程序如何使用MFC类库
unresolved external symbol __beginthreadex错误的解决Win32 Consle Application使用MFC的一些类如CString时编译时相信会很经常遇到 ...