1
0
Fork 0
Browse Source

vault backup: 2022-05-20 17:38:57

master
YuJian 3 years ago
parent
commit
b81c2c3ca6
  1. 18
      数据结构与算法之美/算法之美 - 二分.md
  2. 2
      数据结构与算法之美/算法之美 - 动态规划.md

18
数据结构与算法之美/算法之美 - 二分.md

@ -1,6 +1,6 @@
## 实现一个基于二分查找的整形数组查找 ## 实现一个基于二分查找的整形数组查找
```javascript ```typescript
const indexOf_BinarySearch = (dataArr: number[], num: number): number => { const indexOf_BinarySearch = (dataArr: number[], num: number): number => {
let n1 = 0; let n1 = 0;
let n2 = dataArr.length - 1; let n2 = dataArr.length - 1;
@ -8,14 +8,14 @@ const indexOf_BinarySearch = (dataArr: number[], num: number): number => {
if (n2 === num) return n2; if (n2 === num) return n2;
while (n1 <= n2) { while (n1 <= n2) {
const mid = Math.floor((n1 + n2) / 2); const mid = Math.floor((n1 + n2) / 2);
if (num > dataArr[mid]) { if (num > dataArr[mid]) {
n1 = mid + 1; n1 = mid + 1;
} else if (num < dataArr[mid]) { } else if (num < dataArr[mid]) {
n2 = mid - 1; n2 = mid - 1;
} else { } else {
return mid; return mid;
} }
} }
return -1; return -1;

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

@ -4,7 +4,7 @@
>实际上是 (n - 1) + (n - 2) >实际上是 (n - 1) + (n - 2)
```javascript ```typescript
const Fibonacci_Cycle = (n: number): number => { const Fibonacci_Cycle = (n: number): number => {
if (n <= 0) return 0; if (n <= 0) return 0;
if (n === 1) return n; if (n === 1) return n;

Loading…
Cancel
Save