Common Values of Two Sorted Lists
Lists l1 and l2 are both sorted from smallest to largest. Return a new sorted list holding every value that appears in both, each value listed once even if it repeats.
Linked lists appear in the tests as the list of their values, like [1,2,3]. Each node is a ListNode with .val and .next; the class is already defined for you.
Example 1
l1 [1,2,2,3,5]
l2 [2,2,5,6]
returns [2,5]
Both contain 2 and 5.
Example 2
l1 [1,3]
l2 [2,4]
returns []
Nothing in common.
Constraints
0 <= nodes in each list <= 50-100 <= Node.val <= 100- Both lists are sorted in non-decreasing order
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.