Skip to content

Commit c3381c1

Browse files
Merge pull request wangzheng0822#152 from LYDongD/master
operation optimization
2 parents 9b89bb3 + 66e8cfc commit c3381c1

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

go/binarysearch2.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ func BinarySearch2(nums []int, value int) int {
66
start := 0
77
end := length - 1
88
for start <= end {
9-
mid := (start + end) / 2
9+
mid := start + ((end - start) >> 1)
1010
if nums[mid] > value {
1111
end = mid - 1
1212
} else if nums[mid] < value {
@@ -29,7 +29,7 @@ func BinarySearch3(nums []int, value int) int {
2929
start := 0
3030
end := len(nums) - 1
3131
for start <= end {
32-
mid := (start + end) / 2
32+
mid := start + ((end - start) >> 1)
3333
if nums[mid] > value {
3434
end = mid - 1
3535
} else if nums[mid] < value {

0 commit comments

Comments
 (0)