Skip to content

Commit 522efcb

Browse files
Xinhai WangegonSchiele
authored andcommitted
Update BinarySearch.go (egonSchiele#73)
fix bug(panic for empty array)
1 parent d13ab11 commit 522efcb

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

01_introduction_to_algorithms/Golang/BinarySearch.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,10 @@ package main
22

33
import "fmt"
44

5-
func getBool(i, j int) bool {
6-
if i <= j{
7-
return true
8-
}else {
9-
return false
10-
}
11-
}
12-
135
func checkBin(list []int, i int) bool {
146
low := 0
157
high := len(list) -1
16-
for ok := true;ok ;ok = getBool(low,high) {
8+
for low <= high {
179
mid:= (low+high)/2
1810
if list[mid] == i{
1911
return true

0 commit comments

Comments
 (0)