Day i do not know
This commit is contained in:
11
62. Unique Paths/62. Unique Paths.csproj
Normal file
11
62. Unique Paths/62. Unique Paths.csproj
Normal file
@@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<RootNamespace>_62._Unique_Paths</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
9
62. Unique Paths/Program.cs
Normal file
9
62. Unique Paths/Program.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace _62._Unique_Paths;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine(new Solution().UniquePaths(10,10));
|
||||
}
|
||||
}
|
||||
29
62. Unique Paths/Solution.cs
Normal file
29
62. Unique Paths/Solution.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System.Numerics;
|
||||
|
||||
namespace _62._Unique_Paths;
|
||||
|
||||
public class Solution
|
||||
{
|
||||
public int UniquePaths(int min, int max)
|
||||
{
|
||||
min--;
|
||||
max--;
|
||||
if (min == 0 || max == 0)
|
||||
return 1;
|
||||
if(min > max)
|
||||
{
|
||||
min = min + max;
|
||||
max = min - max;
|
||||
min = min - max;
|
||||
}
|
||||
return (int)(Fact(max + 1, min + max) / Fact(1, min));
|
||||
}
|
||||
|
||||
private BigInteger Fact(int start, int end)
|
||||
{
|
||||
BigInteger res = start;
|
||||
while (++start <= end)
|
||||
res *= start;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user