easyLinked List 0 views

Remove Linked List Elements

Delete every node in a singly-linked list whose value matches a given target.

Given the head of a singly-linked list and an integer val, remove all nodes whose value equals val, and return the resulting list.

Example 1

Input: head = [1,2,6,3,4,5,6], val = 6

Output: [1,2,3,4,5]

Example 2

Input: head = [7,7,7,7], val = 7

Output: []

Explanation: Every node matches the target, so the whole list is removed.

Example 3

Input: head = [], val = 1

Output: []

Explanation: An empty list has nothing to remove.

Constraints

  • The number of nodes in the list is in the range [0, 10^4].
  • 1 <= Node.val <= 50
  • 0 <= val <= 50

Hints

Companies

No companies reported yet.

Discussion

Sign in to join the discussion.

Loading discussion...

Test results

No test cases yet.