Update 0019.删除链表的倒数第N个节点.md
This commit is contained in:
parent
fbe43be1f4
commit
2132ce0e16
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue