From f9342095c9b7d79d8c6debc165a193ddc3e39169 Mon Sep 17 00:00:00 2001 From: eeee0717 Date: Wed, 20 Dec 2023 09:26:14 +0800 Subject: [PATCH 1/2] =?UTF-8?q?Update0491.=E9=80=92=E5=A2=9E=E5=AD=90?= =?UTF-8?q?=E5=BA=8F=E5=88=97=EF=BC=8C=E6=B7=BB=E5=8A=A0C#?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0491.递增子序列.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/problems/0491.递增子序列.md b/problems/0491.递增子序列.md index eb0be005..1aa69a36 100644 --- a/problems/0491.递增子序列.md +++ b/problems/0491.递增子序列.md @@ -614,6 +614,32 @@ object Solution { } } ``` +### C# +```csharp +public class Solution { + public IList> res = new List>(); + public IList path = new List(); + public IList> FindSubsequences(int[] nums) { + BackTracking(nums, 0); + return res; + } + public void BackTracking(int[] nums, int start){ + if(path.Count >= 2){ + res.Add(new List(path)); + } + HashSet hs = new HashSet(); + for(int i = start; i < nums.Length; i++){ + if(path.Count > 0 && path[path.Count - 1] > nums[i] || hs.Contains(nums[i])){ + continue; + } + hs.Add(nums[i]); + path.Add(nums[i]); + BackTracking(nums, i + 1); + path.RemoveAt(path.Count - 1); + } + } +} +```

From eff7a7a9b27cf76d530a253bdfb0b9824e768a3a Mon Sep 17 00:00:00 2001 From: eeee0717 Date: Thu, 21 Dec 2023 09:36:09 +0800 Subject: [PATCH 2/2] =?UTF-8?q?Update0046.=E5=85=A8=E6=8E=92=E5=88=97?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0C#?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0046.全排列.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) 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); + } + } +} +```