diff --git a/problems/0078.子集.md b/problems/0078.子集.md index 5f3654de..06547e3d 100644 --- a/problems/0078.子集.md +++ b/problems/0078.子集.md @@ -443,6 +443,27 @@ object Solution { } } ``` +### C# +```csharp +public class Solution { + public IList> res = new List>(); + public IList path = new List(); + public IList> Subsets(int[] nums) { + BackTracking(nums, 0); + return res; + } + public void BackTracking(int[] nums, int start){ + res.Add(new List(path)); + if(start > nums.Length) return; + for (int i = start; i < nums.Length; i++) + { + path.Add(nums[i]); + BackTracking(nums, i + 1); + path.RemoveAt(path.Count - 1); + } + } +} +```

diff --git a/problems/0090.子集II.md b/problems/0090.子集II.md index 13080cd9..9fc334a4 100644 --- a/problems/0090.子集II.md +++ b/problems/0090.子集II.md @@ -640,6 +640,31 @@ object Solution { } } ``` +### C# +```c# +public class Solution +{ + public IList> res = new List>(); + public IList path = new List(); + public IList> SubsetsWithDup(int[] nums) + { + Array.Sort(nums); + BackTracking(nums, 0); + return res; + } + public void BackTracking(int[] nums, int start) + { + res.Add(new List(path)); + for (int i = start; i < nums.Length; i++) + { + if (i > start && nums[i] == nums[i - 1]) continue; + path.Add(nums[i]); + BackTracking(nums, i + 1); + path.RemoveAt(path.Count - 1); + } + } +} +```