Created
July 29, 2015 09:20
-
-
Save ShinJJang/5fd2fe1791c8d95db917 to your computer and use it in GitHub Desktop.
sort two sorted array, return one sorted array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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