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-3/problems/src/backtracking/Subsets.java at master · abcdvemm/leetcode-3

Expand file tree

/

Subsets.java

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
40 lines (37 loc) · 1.04 KB
/

Subsets.java

Copy path

File metadata and controls

40 lines (37 loc) · 1.04 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
37
38
39
40
package backtracking;
import java.util.ArrayList;
import java.util.List;
/**
* Created by gouthamvidyapradhan on 14/03/2017. Given a set of distinct integers, nums, return all
* possible subsets.
*
* <p>Note: The solution set must not contain duplicate subsets.
*
* <p>For example, If nums = [1,2,3], a solution is:
*
* <p>[ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], [] ]
*/
public class Subsets {
/**
* Main method
*
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
int[] n = {1, 2, 3};
List<List<Integer>> result = new Subsets().subsets(n);
}
public List<List<Integer>> subsets(int[] nums) {
List<List<Integer>> result = new ArrayList<>();
result.add(new ArrayList<>()); // empty subset
for (int i = 0, l = nums.length; i < l; i++) {
for (int j = 0, resLen = result.size(); j < resLen; j++) {
List<Integer> newList = new ArrayList<>(result.get(j));
newList.add(nums[i]);
result.add(newList);
}
}
return result;
}
}
You are visitor 01402792 — 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.