21. Merge Two Sorted Lists (python)

 


Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.

Example:

Input: 1->2->4, 1->3->4
Output: 1->1->2->3->4->4

利用链表的思想,先创建个空链表p,用于存放比较后的结果。然后对传入的两个链表进行比较。小的放在空链表中。然后返回创建的链表。

 

主函数主要是用于测试Solution函数能不能正常运行。先创建两个列表,然后创建两个指针。调用函数,遍历输出Solution函数传回来的链表。


 


posted on 2018-09-10 22:50  shaer  阅读(321)  评论(0编辑  收藏  举报

导航