题解 | #牛牛的递增之旅#
牛牛的递增之旅
https://www.nowcoder.com/practice/e463addab7d548819d6b6483335651b5
简化版的删除重复节点,无需prev指针。
package main
import "fmt"
import . "nc_tools"
/*
* type ListNode struct{
* Val int
* Next *ListNode
* }
*/
func removeDuplicates( head *ListNode ) *ListNode {
if head == nil{
fmt.Println()
return head
}
curr, next := head, head.Next
for next != nil{
if curr.Val == next.Val{
curr.Next = next.Next
next.Next = nil
next = curr.Next
}else{
curr, next = next, next.Next
}
}
return head
}
