my best code in Python


  • 0
    H
    class Solution(object):
        def findMedianSortedArrays(self, nums1, nums2):
            """
            leetCode4. Median of Two Sorted Arrays
            https://leetcode.com/problems/median-of-two-sorted-arrays/#/description
            :type nums1: List[int]
            :type nums2: List[int]
            :rtype: float
            """
            nums1.extend(nums2)
            nums1.sort()
            length=len(nums1)
            if length%2==0:
                return 0.5*(nums1[length//2-1]+nums1[length//2])
            elif length%2==1:
                return nums1[length//2]
            else:
            	return None
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.