GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — leetcode-multi-java/basic/sorting/MergeSort/Main.py at main · gzhcheps/leetcode-multi-java

Expand file tree

/

Main.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
34 lines (29 loc) · 732 Bytes
/

Main.py

Copy path

File metadata and controls

34 lines (29 loc) · 732 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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.