mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-11 04:54:51 +08:00
Update0090.子集2,添加C#
This commit is contained in:
@ -640,6 +640,31 @@ object Solution {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
### C#
|
||||||
|
```c#
|
||||||
|
public class Solution
|
||||||
|
{
|
||||||
|
public IList<IList<int>> res = new List<IList<int>>();
|
||||||
|
public IList<int> path = new List<int>();
|
||||||
|
public IList<IList<int>> SubsetsWithDup(int[] nums)
|
||||||
|
{
|
||||||
|
Array.Sort(nums);
|
||||||
|
BackTracking(nums, 0);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
public void BackTracking(int[] nums, int start)
|
||||||
|
{
|
||||||
|
res.Add(new List<int>(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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
||||||
|
Reference in New Issue
Block a user