Finetune and fix

This commit is contained in:
krahets
2023-08-24 17:48:35 +08:00
parent 628a274b50
commit f524b957d4
4 changed files with 20 additions and 17 deletions

View File

@@ -4,7 +4,7 @@
package chapter_searching
// 二分查找最左一个 target
/* 二分查找最左一个 target */
func binarySearchLeftEdge(nums []int, target int) int {
// 等价于查找 target 的插入点
i := binarySearchInsertion(nums, target)
@@ -16,7 +16,7 @@ func binarySearchLeftEdge(nums []int, target int) int {
return i
}
// 二分查找最右一个 target
/* 二分查找最右一个 target */
func binarySearchRightEdge(nums []int, target int) int {
// 转化为查找最左一个 target + 1
i := binarySearchInsertion(nums, target+1)

View File

@@ -4,7 +4,7 @@
package chapter_searching
// 二分查找插入点(无重复元素)
/* 二分查找插入点(无重复元素) */
func binarySearchInsertionSimple(nums []int, target int) int {
// 初始化双闭区间 [0, n-1]
i, j := 0, len(nums)-1
@@ -26,7 +26,7 @@ func binarySearchInsertionSimple(nums []int, target int) int {
return i
}
// 二分查找插入点(存在重复元素)
/* 二分查找插入点(存在重复元素) */
func binarySearchInsertion(nums []int, target int) int {
// 初始化双闭区间 [0, n-1]
i, j := 0, len(nums)-1