Skip to content

Commit

Permalink
添加(0509.斐波那契数.md):增加typescript版本
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaofei-2020 committed Apr 30, 2022
1 parent f409384 commit 82e8b9e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions problems/0509.斐波那契数.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,29 @@ var fib = function(n) {
};
```

TypeScript

```typescript
function fib(n: number): number {
/**
dp[i]: 第i个斐波那契数
dp[0]: 0;
dp[1]:1;
...
dp[i] = dp[i - 1] + dp[i - 2];
*/
const dp: number[] = [];
dp[0] = 0;
dp[1] = 1;
for (let i = 2; i <= n; i++) {
dp[i] = dp[i - 1] + dp[i - 2];
}
return dp[n];
};
```

### C

动态规划:
```c
int fib(int n){
Expand Down

0 comments on commit 82e8b9e

Please sign in to comment.