diff --git a/go/binarysearch2.go b/go/binarysearch2.go index 145f4f7f..9e3f71e2 100644 --- a/go/binarysearch2.go +++ b/go/binarysearch2.go @@ -6,7 +6,7 @@ func BinarySearch2(nums []int, value int) int { start := 0 end := length - 1 for start <= end { - mid := start + ((end - start) >> 2) + mid := start + ((end - start) >> 1) if nums[mid] > value { end = mid - 1 } else if nums[mid] < value { @@ -29,7 +29,7 @@ func BinarySearch3(nums []int, value int) int { start := 0 end := len(nums) - 1 for start <= end { - mid := (start + end) / 2 + mid := start + ((end - start) >> 1) if nums[mid] > value { end = mid - 1 } else if nums[mid] < value {