Skip to content

Commit

Permalink
82 finish
Browse files Browse the repository at this point in the history
  • Loading branch information
aQua authored and aQua committed Sep 6, 2017
1 parent 84047f1 commit d44f57f
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ type ListNode struct {
}

func deleteDuplicates(head *ListNode) *ListNode {
// 长度 <=1 的 list ,可以直接返回
if head == nil || head.Next == nil {
return head
}

// 处理 head 重复情况
// 上面刚刚检查过了,head != nil && head.Next != nil
if head.Val == head.Next.Val {
val := head.Val
head = head.Next.Next
Expand All @@ -19,9 +22,11 @@ func deleteDuplicates(head *ListNode) *ListNode {
head = head.Next
}

// 值为 val 的 node,已经全部删除了
return deleteDuplicates(head)
}

// 处理 head 后面元素出现重复的情况
head.Next = deleteDuplicates(head.Next)

return head
Expand Down

0 comments on commit d44f57f

Please sign in to comment.