Easy solution using in-built functions beats 96%


  • 0
    P

    I know this idea defeats the purpose of doing this problem but the OJ accepted it beating 96 %.

    class Solution(object):
        def findMedianSortedArrays(self, nums1, nums2):
            
            :type nums1: List[int]
            :type nums2: List[int]
            :rtype: float
            
            res = sorted(nums1 + nums2)
            l = len(res)
            
            if l%2!=0:
                n=l//2
                return res[n]
            elif l%2==0:
                n = l//2
                return float((res[n] + res[n-1]))/2
    

Log in to reply
 

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