A simple python code


  • 0
    K
    class Solution(object):
        def findMedianSortedArrays(self, nums1, nums2):
            
            median=0
            ttl_list = []
            
            while nums1 and nums2:
                if nums1[0]>nums2[0]:
                    ttl_list.append(nums2[0])
                    del nums2[0]
                else:
                    ttl_list.append(nums1[0])
                    del nums1[0]
                    
            if nums1:
                ttl_list+=nums1
            elif nums2:
                ttl_list+=nums2
            
            print ttl_list
            
            if len(ttl_list)%2!=0:
                median = ttl_list[len(ttl_list)/2]
            else:
                median = (float( ttl_list[len(ttl_list)/2] + ttl_list[(len(ttl_list)/2)-1] )) /2
    
                        
                
            return median
            
            
    

Log in to reply
 

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