-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#19: add solution for exercise #78 in rust
1 parent
7679e94
commit 875b777
Showing
1 changed file
with
17 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |