-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
def findMedianSortedArrays(a, b):
if len(a) > len(b):
a, b = b, a
m, n = len(a), len(b)
l, h = 0, m
while l <= h:
i = (l + h) // 2
j = (m + n + 1) // 2 - i
L1 = float('-inf') if i == 0 else a[i-1]
R1 = float('inf') if i == m else a[i]
L2 = float('-inf') if j == 0 else b[j-1]
R2 = float('inf') if j == n else b[j]
if L1 <= R2 and L2 <= R1:
if (m+n) % 2 == 0:
return (max(L1, L2) + min(R1, R2)) / 2.0
else:
return max(L1, L2)
elif L1 > R2:
h = i - 1
else:
l = i + 1
Metadata
Metadata
Assignees
Labels
No labels