Remove Linked List Elements
Linked list
easy
Score: 20
Given the head
of a linked list and an integer key
, remove all the nodes of the linked list that has Node.data == key
, and return the new head
.
Class Node:
data (int)
next (Node)
Input Format
First Parameter - Node head
Second Parameter - number key
Output Format
Return the node.
Example 1:
Input: 1 2 6 7 5 7
7
Output: 1 2 6 5
Explanation:
Here we want to delete node having value 7 , and return the List .
Example 2:
Input: 5 5 5 5 5
5
Output: (NULL)
Constraints:
- The number of nodes in the list is in the range [0, 104].
- 1 <=
Node.data
<= 104 - 0 <=
key
<= 104 - Expected Time Complexity: O(N)
- Expected Space Complexity: O(1)