:type nums1: List[int] :type nums2: List[int] :rtype: float
(self, nums1, nums2)
| 64 | class Solution(object): |
| 65 | |
| 66 | def findMedianSortedArrays(self, nums1, nums2): |
| 67 | """ |
| 68 | :type nums1: List[int] |
| 69 | :type nums2: List[int] |
| 70 | :rtype: float |
| 71 | """ |
| 72 | |
| 73 | length = len(nums1) + len(nums2) |
| 74 | if length <= 2: |
| 75 | return sum(nums1+nums2) / length |
| 76 | raw_length = length |
| 77 | |
| 78 | length = length // 2 |
| 79 | |
| 80 | if raw_length % 2 != 0: |
| 81 | length += 1 |
| 82 | |
| 83 | while length > 1: |
| 84 | |
| 85 | reduce_value = length // 2 |
| 86 | if nums1: |
| 87 | if reduce_value > len(nums1): |
| 88 | reduce_value = len(nums1) |
| 89 | if nums2: |
| 90 | if reduce_value > len(nums2): |
| 91 | reduce_value = len(nums2) |
| 92 | |
| 93 | nums1_k_value = nums1[reduce_value-1] if nums1 else float('inf') |
| 94 | nums2_k_value = nums2[reduce_value-1] if nums2 else float('inf') |
| 95 | |
| 96 | if nums1_k_value < nums2_k_value: |
| 97 | nums1 = nums1[reduce_value:] |
| 98 | else: |
| 99 | nums2 = nums2[reduce_value:] |
| 100 | |
| 101 | length -= reduce_value |
| 102 | |
| 103 | |
| 104 | result = sorted(nums1[:2] + nums2[:2]) |
| 105 | if raw_length % 2 != 0: |
| 106 | return result[0] |
| 107 | |
| 108 | return sum(result[:2]) / 2 |
| 109 | |
| 110 | |
| 111 | # def findMedianSortedArrays(self, nums1, nums2): |
nothing calls this directly
no outgoing calls
no test coverage detected