1
0
Fork 0
Browse Source

vault backup: 2022-05-20 12:07:56

master
YuJian 3 years ago
parent
commit
0a6273f366
  1. 32
      数据结构与算法之美/算法之美 - 动态规划.md

32
数据结构与算法之美/算法之美 - 动态规划.md

@ -1,3 +1,33 @@ @@ -1,3 +1,33 @@
>大问题拆解为小问题,逐级向下拆解
## 用循环实现斐波那契数列
## 用循环实现斐波那契数列
```javascript
const Fibonacci_Cycle = (n: number): number => {
if (n <= 0) return 0;
if (n === 1) return n;
let n1 = -1;
let n2 = -1;
let n3 = 0;
for (let index = 0; index <= n; index++) {
if (index === 0) {
n1 = 0;
n2 = 0;
continue;
}
if (index === 1) {
n1 = 0;
n2 = 1;
continue;
}
n3 = n1 + n2;
n1 = n2;
n2 = n3;
}
return n3;
};
```
Loading…
Cancel
Save