Day i do not know

This commit is contained in:
Electrominch
2022-10-18 00:45:31 +03:00
parent 01c5720116
commit 284b6ff10c
72 changed files with 1256 additions and 12 deletions

View File

@@ -0,0 +1,30 @@
namespace _46._Permutations;
public class Solution
{
public IList<IList<int>> Permute(int[] nums)
{
List<IList<int>> l = new List<IList<int>>();
Recursion(l, new List<int>(), nums.ToHashSet());
return l;
}
private void Recursion(List<IList<int>> result, List<int> cur, HashSet<int> aviable)
{
if(aviable.Count == 0)
{
result.Add(cur);
return;
}
foreach(var av in aviable)
{
var newAviable = aviable.ToHashSet();
newAviable.Remove(av);
var newCur = cur.ToList();
newCur.Add(av);
Recursion(result, newCur, newAviable);
}
}
}