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.

Function Description

Complete the function removeNodes in the editor with the following parameter(s):

  • node listHead: a reference to the root node of the singly-linked list
  • int 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

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: