class Solution: def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None: nums1[0:] = nums1[0:m] nums1.extend(nums2) stop_this = False if(m!=0 and n != 0): first_of_1 = nums1[0] first_of_2 = nums2[0] last_of_2 = nums2[-1] if(first_of_1 > first_of_2 and first_of_1 > last_of_2): nums2.extend(nums1) nums1[0:] = nums2 print("fff=",nums1) for j in range(0,len(nums1)): if(stop_this): break for i in range(0,len(nums1)): if i == len(nums1)-1: break if(nums1[i]>nums1[i+1]): first_val = nums1[i] nums1[i] = nums1[i+1] nums1[i+1] = first_val break if j == len(nums1)-1: stop_this = True if(n == 1 ): nums1[0:] = list(set(nums1)) print(nums1) p88 = Solution() p88.merge([0],0, [1],1)
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter