Accpeted Python 56 ms solution


  • -2
    M
    # 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
            """
            if not (head and head.next):
                return head
                
            cur = head
            while cur:
                while cur.next and cur.val == cur.next.val:
                    cur.next = cur.next.next
                
                cur = cur.next
                
            return head

Log in to reply
 

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