-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ4.py
More file actions
38 lines (30 loc) · 1014 Bytes
/
Q4.py
File metadata and controls
38 lines (30 loc) · 1014 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import sys
class Solution(object):
def findMedianSortedArrays(self, nums1, nums2):
"""
:type nums1: List[int]
:type nums2: List[int]
:rtype: float
"""
n = len(nums1)
m = len(nums2)
if(n>m):
return Solution().findMedianSortedArrays(nums2,nums1)
lMax1=lMax2=rMin1=rMin2=lo=0
hi = 2*n
while(hi>=lo):
c1 = (hi+lo)/2
c2 = m+n - c1
lMax1 = nums1[(c1-1)/2] if (c1!=0) else -sys.maxsize
rMin1 = nums1[c1/2] if (c1!=2*n) else sys.maxsize
lMax2 = nums2[(c2-1)/2] if (c2!=0) else -sys.maxsize
rMin2 = nums2[(c2/2)] if (c2!=2*m) else sys.maxsize
if(lMax1>rMin2):
hi = c1-1
elif(lMax2>rMin1):
lo = c1 +1
else:
break
return (max(lMax1,lMax2)+min(rMin1,rMin2))/2.0
if __name__ == '__main__':
print(sys.maxsize)