filmov
tv
Middle of the Linked List - Leetcode 876 - Python - Daily Problem 17

Показать описание
In this problem you can use a two pointer approach called slow and fast. Slow moves one unit and fast moves two units over every iteration and slow will always end up being the middle/second middle node. So in the end, you just return slow. The time complexity is O(n) as it is just one pass and the space complexity is O(1) as there is no additional space needed.