diff --git a/problems/0046.全排列.md b/problems/0046.全排列.md index 1f5263a7..15e6ae16 100644 --- a/problems/0046.全排列.md +++ b/problems/0046.全排列.md @@ -486,6 +486,37 @@ object Solution { } } ``` +### C# +```csharp +public class Solution +{ + public IList> res = new List>(); + public IList path = new List(); + public IList> Permute(int[] nums) + { + var used = new bool[nums.Length]; + BackTracking(nums, used); + return res; + } + public void BackTracking(int[] nums, bool[] used) + { + if (path.Count == nums.Length) + { + res.Add(new List(path)); + return; + } + for (int i = 0; i < nums.Length; i++) + { + if (used[i]) continue; + used[i] = true; + path.Add(nums[i]); + BackTracking(nums, used); + used[i] = false; + path.RemoveAt(path.Count - 1); + } + } +} +```