Definition for singly-linked list.
Solved at: 220713
Question
You are given the heads of two sorted linked lists list1 and list2.
Merge the two lists in a one sorted list. The list should be made by splicing together the nodes of the first two lists.
Return the head of the merged linked list.
Solution
I misunderstood the question, thinking list1 is type list instead of Node.
- Time Complexity:
- Space Complexity:
Results
Runtime
- 33 ms, faster than 98.24% of Python3 online submissions for Merge Two Sorted Lists.
Memory Usage
- 14 MB, less than 32.33% of Python3 online submissions for Merge Two Sorted Lists.
Other Answers Online
- Time Complexity:
- Space Complexity:
The above solution looks a lot cleaner and Pythonic.
Backlinks (2)
Comments (0)