GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — leetcode-multi-java/basic/sorting/MergeSort/Main.py at main · gzhcheps/leetcode-multi-java Expand file tree/ Copy pathMain.pyMore file actions 34 lines (29 loc) · 732 Bytes / Copy pathMain.pyFile metadata and controls34 lines (29 loc) · 732 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 N = int(input()) nums = list(map(int, input().split())) def merge_sort(nums, left, right): if left >= right: return mid = (left + right) >> 1 merge_sort(nums, left, mid) merge_sort(nums, mid + 1, right) tmp = [] i, j = left, mid + 1 while i <= mid and j <= right: if nums[i] <= nums[j]: tmp.append(nums[i]) i += 1 else: tmp.append(nums[j]) j += 1 while i <= mid: tmp.append(nums[i]) i += 1 while j <= right: tmp.append(nums[j]) j += 1 j = 0 for i in range(left, right + 1): nums[i] = tmp[j] j += 1 merge_sort(nums, 0, N - 1) print(' '.join(list(map(str, nums)))) |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |