Is there any problem with my code ? (AC)


  • 0
    M

    I got an AC with my code ...
    But I was confuse when I reviewed the discussion ...
    Is there any problem with my code ?

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

        num = nums1 + nums2
        num = sorted(num)
        
        l = len(num)
        if l%2==0:
            i=l/2-1
            j=i+1           
            return float(num[i]+num[j])/2
        else:
            return float(num[l/2])
    

    '''

    Thanks.


  • 0

    There are two problems with it:

    • It looks bad because you didn't format it properly.
    • It's not O(log (m+n)).

Log in to reply
 

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