Python simple method


  • 0
    S
    # Definition for singly-linked list.
    # class ListNode(object):
    #     def __init__(self, x):
    #         self.val = x
    #         self.next = None
    
    class Solution(object):
        def deleteDuplicates(self, head):
            """
            :type head: ListNode
            :rtype: ListNode
            """
            dupl = l = ListNode(None)
            while head:
                if head.val != dupl.val:
                    dupl.next = head
                    dupl = dupl.next
                head = head.next
            dupl.next = None
            return l.next
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.