Use a common trick call slow, fast pointer. Because the last n means the distance between last n and the end is n, so we create two pointer, the first is slow, and second is fast, and make fast to n step. And then go thought the list with slow and fast until fast meet the end. At that time, slow ->next is the node we want to delete.
leetcode-19-Remove Nth Node From End of List
最新推荐文章于 2021-01-01 13:13:30 发布