Update 0019.删除链表的倒数第N个节点.md

This commit is contained in:
QuinnDK
2021-05-13 09:03:10 +08:00
committed by GitHub
parent fbe43be1f4
commit 2132ce0e16

View File

@ -112,7 +112,28 @@ class Solution {
}
}
```
Go:
```Go
func removeNthFromEnd(head *ListNode, n int) *ListNode {
result:=&ListNode{}
result.Next=head
var pre *ListNode
cur:=result
i:=1
for head!=nil{
if i>=n{
pre=cur
cur=cur.Next
}
head=head.Next
i++
}
pre.Next=pre.Next.Next
return result.Next
}
```
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)