mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
Update 0019.删除链表的倒数第N个节点.md
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user