My accepted Python solution in 112ms


  • -3
    C

    class Solution:

    # @param {integer[]} nums1
    # @param {integer[]} nums2
    # @return {float}
    def findMedianSortedArrays(self, nums1, nums2):
        all = nums1[:]
        all.extend(nums2)
        
        all.sort()
        if len(all) == 0:
            return None
        elif len(all) == 1:
            return all[0]
        
        if len(all) % 2 == 0:
            median = len(all)/2 - 1
            return (all[median] + all[median + 1]) / 2.0
        else:
            median = len(all)/2
            return all[median]

  • 0
    I

    This is an N*log(N) solution, O(N) at best. I think there is an error with the tests. It should not pass.


Log in to reply
 

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