0%
Subset
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| public List<List<Integer>> subsets(int[] set) { Arrays.sort(set); int totalNumber = 1 << set.length; List<List<Integer>> collection = new ArrayList<List<Integer>>(totalNumber); for (int i=0; i<totalNumber; i++) { List<Integer> subSet = new LinkedList<Integer>(); for (int j=0; j<set.length; j++) { if ((i & (1<<j)) != 0) { subSet.add(set[j]); } } collection.add(subSet); } return collection; }
|