Golang Leetcode 237. Delete Node in a Linked List.go

2019-04-12 11:37:01 浏览数 (1)

版权声明:原创勿转 https://cloud.tencent.com/developer/article/1412924

思路

直接把node的next指向next的next

code

代码语言:javascript复制
func deleteNode(node *ListNode) {
	if node == nil {
		return
	}
	if node.Next == nil {
		node = nil
	}
	node.Val = node.Next.Val
	node.Next = node.Next.Next
}

0 人点赞