0019.删除链表的倒数第 N 个结点
[0019.删除链表的倒数第 N 个结点](https://leetcode.cn/problems/remove-nth-node-from-end-of-list/
方法一:遍历
时间复杂度 $O(n)$,空间复杂度 $O(1)$。
/**
* Definition for singly-linked list.
* type ListNode struct {
* Val int
* Next *ListNode
* }
*/
func removeNthFromEnd(head *ListNode, n int) *ListNode {
dummy := &ListNode{Next: head}
pre, now := dummy, dummy
for ; n > 0; n-- {
now = now.Next
}
for now.Next != nil {
pre, now = pre.Next, now.Next
}
pre.Next = pre.Next.Next
return dummy.Next
}