20. [Linked List] Reverse Linked List II

92. Reverse Linked List IIMedium9.3K420Companies

Given the head of a singly linked list and two integers left and right where left <= right, reverse the nodes of the list from position left to position right, and return the reversed list.

Example 1:

Example 2:

Constraints:

  • The number of nodes in the list is n.

  • 1 <= n <= 500

  • -500 <= Node.val <= 500

  • 1 <= left <= right <= n

Follow up: Could you do it in one pass?

Time: O(N)

Space: O(1)

Last updated