mirror of https://github.com/doocs/leetcode.git
16 lines
470 B
Java
16 lines
470 B
Java
class Solution {
|
|
public List<List<Integer>> subsets(int[] nums) {
|
|
int n = nums.length;
|
|
List<List<Integer>> ans = new ArrayList<>();
|
|
for (int mask = 0; mask < 1 << n; ++mask) {
|
|
List<Integer> t = new ArrayList<>();
|
|
for (int i = 0; i < n; ++i) {
|
|
if (((mask >> i) & 1) == 1) {
|
|
t.add(nums[i]);
|
|
}
|
|
}
|
|
ans.add(t);
|
|
}
|
|
return ans;
|
|
}
|
|
} |