Skip to content

Commit 67791fd

Browse files
authored
Merge pull request #2122 from nirajvenkat/patch-11
Create 0078-subsets.rs
2 parents 5ad7109 + 0b91b53 commit 67791fd

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

rust/0078-subsets.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use std::iter::FromIterator;
2+
3+
impl Solution {
4+
pub fn subsets(nums: Vec<i32>) -> Vec<Vec<i32>> {
5+
let n = nums.len();
6+
7+
Vec::from_iter((0..1 << n).map(|bitmask| {
8+
Vec::from_iter((0..n).filter_map(|i| match (bitmask >> i) & 1 != 0 {
9+
true => Some(nums[i]),
10+
false => None
11+
}))
12+
}))
13+
}
14+
}

0 commit comments

Comments
 (0)