82. Remove Duplicates from Sorted List II (Easy Method Using Just List Functions)
from collections import Counter
class Solution:
    def deleteDuplicates(self, head: Optional[ListNode]) -> Optional[ListNode]:
        lst=[]
        common = set()
        while head:
            lst.append(head.val)
            head=head.next
        ct = dict(Counter(lst))
        for i,j in ct.items():
            if j>1:
                common.add(i)
        new = list(set(lst).difference(common))
        new = sorted(new)
        x=None
        for i in new[::-1]:
            x = ListNode(i,x)
        return x    
Comments (1)