Solved! Leetcode 2487. Remove Nodes From Linked List

Description: Remove Nodes From Linked List

You are given the head of a linked list.

Remove every node which has a node with a greater value anywhere to the right side of it.

Return the head of the modified linked list.

Example 1

Example 2

Constraints

  • The number of the nodes in the given list is in the range [1, 105].
  • 1 <= Node.val <= 105

Solution

Time Complexity

O(n), where n is the number of nodes in a linkedlist

Space Complexity

O(n), where n is the number of nodes in a linkedlist

Rate this post

Leave a Reply