Merge Two Sorted Lists
https://leetcode.com/problems/merge-two-sorted-lists/description/
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.
Thoughts
思路比较容易想,两个指针,那个指针指向的小就把它插入,再把指针往后移动。肯定会有一个先被插完,所以需要再对剩余的没插完的做处理。
Code
Analysis
做题耗时7min
时间复杂度O(m + n)
Last updated
Was this helpful?