Skip to content

Instantly share code, notes, and snippets.

@abozhilov
Created July 12, 2013 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abozhilov/5985948 to your computer and use it in GitHub Desktop.
Save abozhilov/5985948 to your computer and use it in GitHub Desktop.
def merge(list1, list2):
res = []
while len(list1) and len(list2):
if list1[-1] > list2[-1]:
res.append(list1.pop())
else:
res.append(list2.pop())
res.reverse()
return list1 + list2 + res
def merge_sort(arr):
m = len(arr) // 2
if m == 0:
return arr
return merge(merge_sort(arr[:m]), merge_sort(arr[m:]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment