Add the section of binary search insertion. (#671)

Refactor the section of binary search edge.
Finetune the figures of binary search.
This commit is contained in:
Yudong Jin
2023-08-04 05:16:56 +08:00
committed by GitHub
parent 3d81b2d954
commit 71074d88f6
52 changed files with 546 additions and 621 deletions
@@ -22,15 +22,3 @@ func TestBinarySearch(t *testing.T) {
t.Errorf("目标元素 6 的索引 = %d, 应该为 %d", actual, expected)
}
}
func TestBinarySearchEdge(t *testing.T) {
target := 6
nums := []int{1, 3, 6, 6, 6, 6, 6, 10, 12, 15}
// 二分查找最左一个元素
indexLeft := binarySearchLeftEdge(nums, target)
fmt.Println("数组中最左一个元素 6 的索引 = ", indexLeft)
// 二分查找最右一个元素
indexRight := binarySearchRightEdge(nums, target)
fmt.Println("数组中最右一个元素 6 的索引 = ", indexRight)
}