Skip to content

Commit

Permalink
#19: add solution for exercise #78 in rust
Browse files Browse the repository at this point in the history
gabrielvictorcf authored and gosiqueira committed Nov 1, 2022
1 parent 7679e94 commit 875b777
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions rust/backtracking/0078-subsets.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
impl Solution {
pub fn subsets(mut nums: Vec<i32>) -> Vec<Vec<i32>> {
if nums.is_empty(){
return vec![vec![]];
}

let last = nums.pop().unwrap();
let remain_subsets = Self::subsets(nums);
let mut answers = remain_subsets.clone();
for mut set in remain_subsets {
set.push(last);
answers.push(set);
}

answers
}
}

0 comments on commit 875b777

Please sign in to comment.