Subclasses
2600 ワード
Given a collection of numbers, return all possible subclasses.
1 public class Solution {
2 public List<List<Integer>> permute(int[] num) {
3 ArrayList<List<Integer>> result = new ArrayList<List<Integer>>();
4 ArrayList<Integer> row = null;
5 if(num == null ||num.length == 0) return result;
6 long size = (long)Math.pow(2, num.length);
7 for(long i = 0; i < size; i ++){
8 row = new ArrayList<Integer>();
9 for(int j = 0; j < num.length; j ++){
10 if((i >> j) % 2 == 1) row.add(num[j]);
11 }
12 result.add(row);
13 }
14 return result;
15 }
16 }