Category: in_place_modification_linked_list
-
LeetCode 24: Swap Nodes in Pairs
link With four pointers (a, b, c, d) we can swap (b, c) in-place. Since head might change, we introduce a dummy node to simplify edge-case handling. Time: , space: .
-
LeetCode 1474: Delete N Nodes After M Nodes of a Linked List
link With (prev, curr) pointers, we skip nodes and then delete nodes. Time: , space: .
-
LeetCode 725: Split Linked List in Parts
link First we find the expected group sizes from the length of the list and k and then copy the heads of the groups as we do a second pass. Time: , space: .
-
LeetCode 2074: Reverse Nodes in Even Length Groups
link Two pass We first collect the groups in a list and then connect the groups. If a group has even size we also reverse it. Time: , space: . One pass For the groups we have two types of operations: If the count of nodes processed by an operation is smaller than the expected…
-
LeetCode 92: Reverse Linked List II
link One pass We jump to the left node and reverse (right-left+1) number of nodes. We then fix two pointers: To simplify the (prev, curr) logic we introduce a dummy node. Time: , space: .
-
LeetCode 25: Reverse Nodes in k-Group
link Two pass From the length of the list we find how many -groups need to be reversed and we reverse each -group in sequence. While reversing a -group, we have two types of operations: Time: , space: . One pass While reversing a -group, if nodes got reversed where , we know we have…