LeetCode in Java - Reverse Linked List II

Опубликовано: 28 Октябрь 2024
на канале: Edvin He
31
1

#List #LinkedList #InPlace

Using the below ways without allocating the extra space,
Loop over the list to get the parent node of the m-th node and child node of the n-th node
Break the list into three parts, first part is head to the parent node of m-th node, second part is m-th node to n-th node, third part is child of n-th node till the end of the Linked List
Reverse the second part, i.e. the list between m-th node and n-th node
Combine the first part, reversed second part and third part together
to solve this LeetCode Reverse Linked List II problem in Java.

Please subscribe, like and comment to let us learn from each other.

BGM: https://www.bensound.com