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); + } + } +} +```