Simple 7 line python solution - 84ms


  • 1
    S
    class Solution:
        # @param {ListNode} head
        # @return {ListNode}
        def deleteDuplicates(self, head):
            cur = head
            while cur is not None:
                if cur.next is None: return head
                if cur.val == cur.next.val:
                    cur.next = cur.next.next
                else:
                    cur = cur.next
            return head

  • 1
    C

    Nice solution, here is a concise version:

    def deleteDuplicates(self, head):
        node = head
        while node and node.next:
            if node.val == node.next.val:
                node.next = node.next.next
            else:
                node = node.next
        return head

  • 0
    J

    it dismiss the condition [1]


Log in to reply
 

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