nums1 = [1, 2, 4, 6, 8] nums2 = [3, 5, 7, 10, 12, 15, 23] # res = [] # while nums1 and nums2: # if nums1[0] < nums2[0]: # res.append(nums1.pop(0)) # else: # res.append(nums2.pop(0)) left, right = 0, 0 res = [] while left < len(nums1) and right < len(nums2): if nums1[left] < nums2[right]: res.append(nums1[left]) left += 1 else: res.append(nums2[right]) right += 1 temp = nums1[left:] + nums2[right:] res += temp print(res)
标签:打擂台,right,res,append,nums1,nums2,left From: https://www.cnblogs.com/demo-deng/p/17223627.html