From 522efcbc3190a5bed5564980c71451b4c350711c Mon Sep 17 00:00:00 2001 From: Xinhai Wang Date: Thu, 19 Jul 2018 07:00:44 +0800 Subject: [PATCH] Update BinarySearch.go (#73) fix bug(panic for empty array) --- 01_introduction_to_algorithms/Golang/BinarySearch.go | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/01_introduction_to_algorithms/Golang/BinarySearch.go b/01_introduction_to_algorithms/Golang/BinarySearch.go index e39e6c5..4fa3c43 100644 --- a/01_introduction_to_algorithms/Golang/BinarySearch.go +++ b/01_introduction_to_algorithms/Golang/BinarySearch.go @@ -2,18 +2,10 @@ package main import "fmt" -func getBool(i, j int) bool { - if i <= j{ - return true - }else { - return false - } -} - func checkBin(list []int, i int) bool { low := 0 high := len(list) -1 - for ok := true;ok ;ok = getBool(low,high) { + for low <= high { mid:= (low+high)/2 if list[mid] == i{ return true