package main import . "nc_tools" /* //递归 func deleteDuplicates( head *ListNode ) *ListNode { // write code here if head == nil || head.Next == nil { return head } head.Next = deleteDuplicates(head.Next) if head.Val == head.Next.Val { head = head.Next } return head } */ //迭代 func deleteDuplicates( head *ListNode) *ListNode { if head == nil || head.Next == nil { return head } cur := head for cur.Next != nil { if cur.Val == cur.Next.Val { cur.Next = cur.Next.Next } else { cur = cur.Next } } return head }