Merge pull request #1660 from xiaoyu2018/master

分别添加0509、0070、0746、0062C#版本
This commit is contained in:
程序员Carl
2022-09-28 18:42:19 +08:00
committed by GitHub
4 changed files with 101 additions and 0 deletions

View File

@ -452,5 +452,25 @@ object Solution {
}
```
### c#
```c#
public class Solution
{
public int UniquePaths(int m, int n)
{
int[] dp = new int[n];
for (int i = 0; i < n; i++)
dp[i] = 1;
for (int i = 1; i < m; i++)
for (int j = 1; j < n; j++)
dp[j] += dp[j - 1];
return dp[n - 1];
}
}
```
-----------------------
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>

View File

@ -425,5 +425,25 @@ object Solution {
}
```
### C#
```c#
public class Solution {
public int ClimbStairs(int n) {
if(n<=2) return n;
int[] dp = new int[2] { 1, 2 };
for (int i = 3; i <= n; i++)
{
int temp = dp[0] + dp[1];
dp[0] = dp[1];
dp[1] = temp;
}
return dp[1];
}
}
```
-----------------------
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>

View File

@ -370,5 +370,45 @@ object Solution {
}
```
### C#
动态规划:
```c#
public class Solution
{
public int Fib(int n)
{
if(n<2) return n;
int[] dp = new int[2] { 0, 1 };
for (int i = 2; i <= n; i++)
{
int temp = dp[0] + dp[1];
dp[0] = dp[1];
dp[1] = temp;
}
return dp[1];
}
}
```
递归:
```c#
public class Solution
{
public int Fib(int n)
{
if(n<2)
return n;
return Fib(n-1)+Fib(n-2);
}
}
```
-----------------------
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>

View File

@ -370,5 +370,26 @@ object Solution {
}
```
### C#
```c#
public class Solution
{
public int MinCostClimbingStairs(int[] cost)
{
int[] dp=new int[2] { cost[0], cost[1] };
for (int i = 2; i < cost.Length; i++)
{
int temp = Math.Min(dp[0], dp[1])+cost[i];
dp[0]=dp[1];
dp[1]=temp;
}
return Math.Min(dp[0],dp[1]);
}
}
```
-----------------------
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>