Skip to content

Commit

Permalink
添加0509斐波那契数C#版本
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyu2018 committed Sep 25, 2022
1 parent f7d5b71 commit f48f7b0
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions problems/0509.斐波那契数.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>

0 comments on commit f48f7b0

Please sign in to comment.