Single Pointer
1 | class Solution { |
Remarks:
- Use a dummy node to avoid only one node
- TC: $O(L)$, L is the length of the list.
Slow and Fast Pointer
1 | class Solution { |
Remarks:
- Set to pointers: slow and fast, so only go through the list for one time.
- TC: $O(L)$