func removeNthFromEnd(head *ListNode, n int) *ListNode {
p, q := head, head
for ;n >= 0 && p!=nil;n--{
p = p.Next
}
if p == nil && n == 0{
return head.Next
}
for ;p!= nil;p=p.Next{
q = q.Next
}
q.Next = q.Next.Next
return head
}
作者:mu-yu-ting-feng-4
链接:https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/solution/golang-0ms10022m64-by-mu-yu-ting-feng-4/
来源:力扣(LeetCode)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
有疑问加站长微信联系(非本文作者)