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,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>_46._Permutations</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,12 @@
namespace _46._Permutations;
internal class Program
{
static void Main(string[] args)
{
var arr = new int[] { 1,2,3 };
var l = new Solution().Permute(arr);
foreach (var row in l)
Console.WriteLine(String.Join(" ", row));
}
}

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