Few changes in Swift Code (#191)

* Replaced the confusing construction

* The algorithm works faster than the previous version
This commit is contained in:
Kostarev Kirill
2021-03-14 18:42:14 +03:00
committed by GitHub
parent c1c68d9d2a
commit fec65db129
2 changed files with 8 additions and 9 deletions

View File

@@ -8,7 +8,7 @@ func binarySearch <T: Comparable>(_ list: [T], item: T) -> Int? {
// While you haven't narrowed it down to one element ...
while low <= high {
//... check the middle element
let mid = low + (high - low) / 2
let mid = (low + high) / 2
let guess = list[mid]
// Found the item.
if guess == item {