83. Remove Duplicates from Sorted List
Last updated
Last updated
Input: head = [1,1,2]
Output: [1,2]Input: head = [1,1,2,3,3]
Output: [1,2,3]// code here.
type ListNode struct {
Val int
Next *ListNode
}
func deleteDuplicates(head *ListNode) *ListNode {
if head == nil || head.Next == nil {
return head
}
for p := head; p != nil; p = p.Next {
q := p.Next
for q != nil && p.Val == q.Val {
q = q.Next
}
p.Next = q
}
return head
}