Is this a cheated solution?


  • -2
    J

    class Solution(object):

    def findMedianSortedArrays(self, nums1, nums2):
        l = sorted(nums1 + nums2)
        if (len(l) % 2) == 0:
            return (l[len(l) / 2] + l[len(l) / 2 - 1]) / 2.0
        else:
            return l[len(l) / 2]

  • 0
    W

    Well, this is O((m + n)lg(m + n)), there are faster ones like O(m + n) and O(lg(m + n)).


  • 0

    Not cheated one, but slow one. As wenlong9 said, this is a O((m+n)*log(m+n)) solution. O(m+n) is quite straight forward. And the follow up requires O(log(m+n)).


Log in to reply
 

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