Merge two sorted linked lists and return it as a new sorted list. The new list should be made by splicing together the nodes of the first two lists.
Example:
1 | Input: 1->2->4, 1->3->4 |
归并
和归并排序方法一样, 2个链表就创立2个指针. 比较哪个指针指向的元素小再插入, 同时该指针要向后移一位.
1 | /** |
Merge two sorted linked lists and return it as a new sorted list. The new list should be made by splicing together the nodes of the first two lists.
Example:
1 | Input: 1->2->4, 1->3->4 |
和归并排序方法一样, 2个链表就创立2个指针. 比较哪个指针指向的元素小再插入, 同时该指针要向后移一位.
1 | /** |