Middle of the Linked List
|Last edited: 2024-5-9
ID
876
Data Type
Linked List
Difficulty
Easy
Tags
Fast & Slow Pointers
Completed Date
May 9, 2024
Preference
💸😭 Poverty Tears
Given the head of a singly linked list, return the middle node of the linked list.
If there are two middle nodes, return the second middle node.
Example 1:
notion image
Example 2:
notion image
Constraints:
  • The number of nodes in the list is in the range [1, 100].
  • 1 <= Node.val <= 100

题解

快慢指针,没什么好说的,注意边界条件