Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit eff7a7a

Browse files
committed
Update0046.全排列,添加C#
1 parent f934209 commit eff7a7a

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

‎problems/0046.全排列.md‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,37 @@ object Solution {
486486
}
487487
}
488488
```
489+
### C#
490+
```csharp
491+
public class Solution
492+
{
493+
public IList<IList<int>> res = new List<IList<int>>();
494+
public IList<int> path = new List<int>();
495+
public IList<IList<int>> Permute(int[] nums)
496+
{
497+
var used = new bool[nums.Length];
498+
BackTracking(nums, used);
499+
return res;
500+
}
501+
public void BackTracking(int[] nums, bool[] used)
502+
{
503+
if (path.Count == nums.Length)
504+
{
505+
res.Add(new List<int>(path));
506+
return;
507+
}
508+
for (int i = 0; i < nums.Length; i++)
509+
{
510+
if (used[i]) continue;
511+
used[i] = true;
512+
path.Add(nums[i]);
513+
BackTracking(nums, used);
514+
used[i] = false;
515+
path.RemoveAt(path.Count - 1);
516+
}
517+
}
518+
}
519+
```
489520

490521
<p align="center">
491522
<a href="https://programmercarl.com/other/kstar.html" target="_blank">

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /