GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — leetcode/code/lc78.java at master · mJackie/leetcode

Expand file tree

/

lc78.java

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
36 lines (35 loc) · 1.09 KB
/

lc78.java

Copy path

File metadata and controls

36 lines (35 loc) · 1.09 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package code;
/*
* 78. Subsets
* 题意:求数组子集
* 难度:Medium
* 分类:Array, Backtracking, Bit Manipulation
* 思路:回溯法
* Tips:和lc46,39作比较.要找出子集,所以每次backtracking直接添加进res
*/
import java.util.ArrayList;
import java.util.List;
public class lc78 {
public static void main(String[] args) {
int[] nums= {1,2,3};
System.out.println(subsets(nums).toString());
}
public static List<List<Integer>> subsets(int[] nums) {
List<List<Integer>> res = new ArrayList<List<Integer>>();
res.add(new ArrayList<>());
if(nums.length==0)
return res;
backtracking(res,nums,new ArrayList(),-1);
return res;
}
public static void backtracking(List<List<Integer>> res, int[] nums, List l, int start){
if(start>=nums.length)
return;
for (int i = start+1; i < nums.length ; i++) {
l.add(nums[i]);
res.add(new ArrayList<Integer>(l));
backtracking(res,nums,l,i);
l.remove((Integer)nums[i]);
}
}
}
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.