Remove Linked List Elements
Remove every node whose value equals val and return the head of the resulting list. The head itself may be removed, and the list may end up empty. 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 [1,2,6,3,6]
val 6
returns [1,2,3]
Both 6s are removed.
Example 2
head [7,7]
val 7
returns []
Everything is removed.
Constraints
0 <= number of nodes <= 100-100 <= Node.val <= 100-100 <= val <= 100
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.