# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
# time O(N)  space O(1)
    def deleteDuplicates(self, head: ListNode) -> ListNode:
        if not head or not head.next:
            return head 
        cur = head 
        # (1)if current val is == next val ,keep move next forward, until first time next is different 
        #(2)connect current's next to next
        #(3) move current to its next
        while cur:
            nxt = cur.next 
            while nxt and cur.val == nxt.val:  
                nxt = nxt.next 
            cur.next = nxt
            cur = nxt 
        return head