O((M+N)/2 was accepted. lol.


  • -1
    D

    class Solution:
    def findMedianSortedArrays(self, nums1, nums2):
    """
    :type nums1: List[int]
    :type nums2: List[int]
    :rtype: float
    """

        x = 0
        n1 = 0
        n2 = 0
        finalnums = []
        while(x < ((len(nums1) + len(nums2)+ 1)/2 ) ):
            if(len(nums1)== n1):
                finalnums.append(nums2[n2])
                n2 +=1
            elif(len(nums2)==n2):
                finalnums.append(nums1[n1])
                n1 +=1
            elif(nums1[n1]<nums2[n2]):
                finalnums.append(nums1[n1])
                n1 +=1
            else:
                finalnums.append(nums2[n2])
                n2 +=1
            x+=1
    
        if((len(nums1) + len(nums2)) % 2 == 0):
            return (finalnums[-1] + finalnums[-2])/2
        else:
            return float(finalnums[-1])

Log in to reply
 

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