Merge two sorted lists python Solution

Merge Two Sorted Lists in Python

PythonServer Side ProgrammingProgramming

Suppose we have two sorted lists A and B. We have to merge them and form only one sorted list C. The size of lists may different.

For an example, suppose A = [1,2,4,7] and B = [1,3,4,5,6,8], then merged list C will be [1,1,2,3,4,4,5,6,7,8]

We will solve this using recursion. So the function will work like below

  • Suppose the lists A and B of function merge[]
  • if A is empty, then return B, if B is empty, then return A
  • if value in A

Chủ Đề