leetcode:83. Remove Duplicates f
2018-08-22 本文已影响0人
唐僧取经
83. Remove Duplicates from Sorted List
Description
Given a sorted linked list, delete all duplicates such that each element appear only once.
Example 1:
Input: 1->1->2
Output: 1->2
Example 2:
Input: 1->1->2->3->3
Output: 1->2->3
Answer
func deleteDuplicates(head *ListNode) *ListNode {
var temp *ListNode
temp = head
for head != nil && head.Next != nil {
if head.Val == head.Next.Val {
head.Next = head.Next.Next
} else {
head = head.Next
}
}
return temp
}