Skip to content

Instantly share code, notes, and snippets.

@ShinJJang
Created July 29, 2015 09:20
Show Gist options
  • Save ShinJJang/5fd2fe1791c8d95db917 to your computer and use it in GitHub Desktop.
Save ShinJJang/5fd2fe1791c8d95db917 to your computer and use it in GitHub Desktop.
sort two sorted array, return one sorted array
def sort(a, b):
a_index=0
b_index=0
result = []
while a_index < len(a) or b_index < len(b):
if b_index >= len(b):
result.append(a[a_index])
a_index+=1
elif a_index >= len(a):
result.append(b[b_index])
b_index+=1
elif a[a_index] < b[b_index]:
result.append(a[a_index])
a_index+=1
else:
result.append(b[b_index])
b_index+=1
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment