1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
// @Title: 删除排序链表中的重复元素 (Remove Duplicates from Sorted List)
// @Author: 15816537946@163.com
// @Date: 2019-11-20 22:28:02
// @Runtime: 4 ms
// @Memory: 3.1 MB
/**
 * Definition for singly-linked list.
 * type ListNode struct {
 *     Val int
 *     Next *ListNode
 * }
 */
func deleteDuplicates(head *ListNode) *ListNode {
	if head == nil || head.Next == nil {
		return  head
	}
	head.Next = deleteDuplicates(head.Next)
	if head.Val == head.Next.Val {
		return  head.Next
	}
	return head
}