Skip to content

Commit 22742fb

Browse files
committed
Try to fix BinarySearch.scala
1 parent 0d3570c commit 22742fb

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/scala/BinarySearch.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ def binarySearch(data: Seq[Int], target: Int): Option[Int] = {
44

55
@tailrec
66
def search(left: Int, right: Int): Option[Int] = {
7-
8-
if (left > right) None
9-
else {
7+
if (left > right) {
8+
None
9+
} else {
1010
val middle: Int = (left + right) / 2
1111
if (data(middle) == target) Some(middle)
1212
else if (data(middle) < target) search(middle + 1, right)
@@ -18,7 +18,6 @@ def binarySearch(data: Seq[Int], target: Int): Option[Int] = {
1818
}
1919

2020
object Main extends App {
21-
2221
val data: Seq[Int] = Seq(0, 1, 3, 5, 6, 7, 8, 9, 10, 11, 12)
2322
val value: Int = 11
2423
println(s"Value '$value' found in position '${binarySearch(data, value).get}'")

0 commit comments

Comments
 (0)