01 · Question
Given the head of a singly linked list, return a new list with the same values.
02 · Solution
1def copy_list(head: Optional[ListNode]) -> Optional[ListNode]:2 dummy = ListNode(0)3 tail = dummy4 cur = head5 while cur:6 tail.next = ListNode(cur.val)7 tail = tail.next8 cur = cur.next9 return dummy.next