classSolution{ public List<List<Integer>> subsets(int[] nums) { List<List<Integer>> result = new ArrayList<>(); if (nums == null) { return result; } int len = nums.length; int max = 1; for (int i = 0; i < len - 1; i++) { max = (max << 1) + 1; } for (int i = 0; i <= max; i++) { List<Integer> subset = new ArrayList<>(); int tmp = i; for (int j = 0; j < len; j++) { if ((tmp & 1) != 0) { subset.add(nums[j]); } tmp >>= 1; } result.add(subset); } return result; }