原题
https://leetcode.com/problems/remove-nth-node-from-end-of-list/
Given a linked list, remove the n-th node from the end of list and return its head.
Follow up:
Could you do this in one pass?
思路
使用两个指针fast以及slow,fast先出发,slow相隔n位再出发。当fast走到尽头时slow跳过下一指针即可。
代码
1 | # Definition for singly-linked list. |