# Merge Two Sorted [[linked-list|Lists]]
https://leetcode.com/problems/merge-two-sorted-lists/
- User `prehead` to initiate the iteration
- Utilize the fact that when one list is duplicated, the other list can be immediately appended.
```python
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
prehead = ListNode(-1)
prev = prehead
while list1 and list2:
if list1.val <= list2.val:
prev.next = list1
list1 = list1.next
else:
prev.next = list2
list2 = list2.next
prev = prev.next
prev.next = list1 if list1 else list2
return prehead.next
```