Skip to content

Commit 30bec57

Browse files
committed
p78
1 parent 947b58e commit 30bec57

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/p78.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
pub fn run() {
2+
for i in [
3+
[1,2,3].to_vec(),
4+
[0].to_vec()
5+
] {
6+
println!("{:?}", subsets(i));
7+
}
8+
}
9+
10+
pub fn subsets(nums: Vec<i32>) -> Vec<Vec<i32>> {
11+
(0..((2f32.powi(nums.len() as i32) as i32))).into_iter().map(|i| nums.iter().enumerate().filter(|(index, _)| ((i >> index) & 1) == 1).map(|x| *x.1).collect::<Vec<i32>>()).collect()
12+
}

0 commit comments

Comments
 (0)