Problem
Given a non-empty, singly linked list with head node head
, return a middle node of linked list.
If there are two middle nodes, return the second middle node.
Examples
1 | Input: [1,2,3,4,5] |
Note
- The number of nodes in the given list will be between
1
and100
.
Solution
Method: Two Pointers
Time Complexity: O(n)
Space Complexity: O(1)
1 | # Definition for singly-linked list. |