<jupyter_start><jupyter_text>MediumGiven a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.Example 1:    Input: 1->2->3->3->4->4->5    Output: 1->2->5Example 2:    Input: 1->1->1->2->3    Output: 2->3  Thoughtset a current pointer, previous point and a flag. If we found duplicated number, then we set flag as 1. And the current pointer would keep moving forward until we found the number is not the same. Then we go down to the next line of the code. We can see that if flag equals 1, then the previous.next would be the current.next since we want to eliminate evey number which are duplicated.After the while loop, we need to check if flag is 1 or not because the duplicated number might go thourgh the list till the end. Therefore, we need to check whether the duplicated flag is on or not.<jupyter_code>class Solution:
    def deleteDuplicates(self, head: ListNode) -> ListNode:
        if not head or not head.next: return head
        
        dummy = pre = ListNode(0)
        dummy.next = head
        
        cur = head
        flag = 0
        
        while cur and cur.next:
            if cur.val == cur.next.val:
                cur = cur.next
                flag = 1
            else:
                if flag == 1:
                    pre.next = cur.next
                    cur = cur.next
                    flag = 0 
                else:
                    pre = cur
                    cur = cur.next
        if flag == 1:
            pre.next = cur.next
            cur = cur.next       
        
            
            
        
        return dummy.next<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.06599286563614744, 'fraction_numerical': 0.016646848989298454, 'mean_word_length': 1.679936305732484, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '115051', 'license': 'BSD-2-Clause', 'n_tokens_mistral': 459, 'n_tokens_neox': 429, 'n_words': 199, 'path': '82. Remove Duplicates from Sorted List II.ipynb', 'repo_name': 'kkoo1122/Leetcode_Practice', 'size': '1682'}