diff --git a/problems/0078.子集.md b/problems/0078.子集.md index e6cc668b..3e98311e 100644 --- a/problems/0078.子集.md +++ b/problems/0078.子集.md @@ -292,6 +292,30 @@ function subsets(nums: number[]): number[][] { }; ``` +## Rust + +```Rust +impl Solution { + fn backtracking(result: &mut Vec>, path: &mut Vec, nums: &Vec, start_index: usize) { + result.push(path.clone()); + let len = nums.len(); + // if start_index >= len { return; } + for i in start_index..len { + path.push(nums[i]); + Self::backtracking(result, path, nums, i + 1); + path.pop(); + } + } + + pub fn subsets(nums: Vec) -> Vec> { + let mut result: Vec> = Vec::new(); + let mut path: Vec = Vec::new(); + Self::backtracking(&mut result, &mut path, &nums, 0); + result + } +} +``` + ## C ```c