2095. Delete the Middle Node of a Linked List
Medium
Previous2091. Removing Minimum and Maximum From ArrayNext2116. Check if a Parentheses String Can Be Valid
Last updated
Medium
Last updated
You are given the head
of a linked list. Delete the middle node, and return the head
of the modified linked list.
The middle node of a linked list of size n
is the ⌊n / 2⌋th
node from the start using 0-based indexing, where ⌊x⌋
denotes the largest integer less than or equal to x
.
For n
= 1
, 2
, 3
, 4
, and 5
, the middle nodes are 0
, 1
, 1
, 2
, and 2
, respectively.
Example 1:
Example 2:
Example 3:
Constraints:
The number of nodes in the list is in the range [1, 105]
.
1 <= Node.val <= 105
這題的話,可以透過三個指標來解,當fast跑到最後一個節點時,slow正好是位於中間需要被刪除的點。透過將pre.Next改為slow.Next,來將slow排除於linked list外。