Delete Nodes Greater Than X
Given a singly linked list and an integer, x, remove nodes greater than x.
Example:
List = 100 → 105 → 50
x = 100
List becomes 100 → 50
Return a reference to the root node of the list after removing 105.
Complete the function removeNodes in the editor with the following parameter(s):
node listHead: a reference to the root node of the singly-linked listint x: the maximum value to be included in the returned singly-linked list
Returns:
node: a reference to the root node of the final list
Constraints
- 1 ≤ n, x ≤ 105
- 1 ≤ SinglyLinkedListNode values ≤ 105
1Example 1
The nodes of the list are traversed and any node with a value greater than x is removed.
In this case, the node with value 105 is greater than x and is therefore removed, resulting in the final list: 100 → 50.
Constraints
Limits and guarantees your solution can rely on.
1 ≤ n, x ≤ 1051 ≤ SinglyLinkedListNode values ≤ 105