Group Equal Values
Rearrange the list so that all nodes with the same value sit next to each other. Order the groups by where each value first appeared in the original list. Return the head. For 3 -> 1 -> 3 -> 2 -> 1 the answer is 3 -> 3 -> 1 -> 1 -> 2. The list is passed in as head.
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
head [3,1,3,2,1]
returns [3,3,1,1,2]
Groups appear in the order 3, 1, 2.
Constraints
0 <= number of nodes <= 100-100 <= Node.val <= 100
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.