Problem Description
Given a sorted list, delete all the duplicate elements, so that each element occurs only once.
Example 1:
Input: 1-> 1-> 2
Output: 1-> 2
Example 2:
Input: 1-> 1-> 2-> 3-> 3
Output: 1-> 2-> 3
Double pointer Code
class Solution:
def deleteDuplicates(self, head: ListNode) -> ListNode:
p = head
q = head
while q:
if p.val != q.val:
p.next = q
p = p.next
q = q.next
if p:
p.next = None
return head