Skip to content

Commit d786467

Browse files
committed
fixed empty array case, added test
1 parent c79a2d3 commit d786467

File tree

5 files changed

+5
-1
lines changed

5 files changed

+5
-1
lines changed
File renamed without changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def bin_search(self, arr, num, fits=lambda a, b: a == b, le=lambda a, b: a <= b)
1212
rg = md - 1
1313
md = (lf + rg) // 2
1414

15-
if fits(arr[md], num):
15+
if arr and fits(arr[md], num):
1616
# searching the biggest possible step to each side and do it as many times as possible
1717
left_step, right_step = 1 << 20, 1 << 20
1818
lf_offset, rg_offset = 0, 0

py3/hard/median/test/test3

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"input": "\n1",
3+
"output": "1.0"
4+
}

0 commit comments

Comments
 (0)