Short and simple python solution


  • 0
    # 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
            """
            pre = ListNode(None)
            walk = head
            while walk:
                if walk.val == pre.val:
                    pre.next = walk.next
                else:
                    pre = walk
                walk = walk.next
            return head

  • 0
    Z

    great, what structure is it? It doesn't seem like recursive


Log in to reply
 

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