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函数传回来的链表。



苟有恒,何必三更眠五更起;最无益,莫过一日暴十日寒。
原文地址:https://www.cnblogs.com/shaer/p/9623752.html