Spaces:
Running
Running
| def merge_sorted(left: list[int], right: list[int]) -> list[int]: | |
| """Merge two sorted lists into one sorted list.""" | |
| merged = [] | |
| i = 0 | |
| j = 0 | |
| # BUG: should continue while BOTH lists still have elements, | |
| # and then append remainders. | |
| while i < len(left) and j < len(right): | |
| if left[i] < right[j]: | |
| merged.append(left[i]) | |
| i += 1 | |
| else: | |
| merged.append(right[j]) | |
| j += 1 | |
| return merged | |