Given the head of a singly linked list and an integer val, remove all the nodes of the linked list that has Node.val == val, and return the new head.
Example:
Input: head =[1, 2, 6, 3, 4, 5, 6], val = 6 Output:[1, 2, 3, 4, 5]
Note:
Your algorithm should run in O(n) time and use O(1) extra space.
Walkthroughs of the solution. Try the steps first, then watch to compare approaches.
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check