Share my simple python solution

  • 0
    # Definition for singly-linked list.
    # class ListNode(object):
    #     def __init__(self, x):
    #         self.val = x
    # = None
    class Solution(object):
        def deleteDuplicates(self, head):
            :type head: ListNode
            :rtype: ListNode
            if not head or not
                return head
            retNode, saveNode, prevNode, currNode, nextNode = None, None, None, head,
            while True:
                if (not prevNode or prevNode.val != currNode.val) and (not nextNode or currNode.val != nextNode.val):
                    if not retNode:
                        saveNode = currNode
                        retNode = saveNode
               = currNode
                        saveNode =
                if not nextNode: break
                prevNode, currNode, nextNode = currNode, nextNode,
            if saveNode: = None
            return retNode

Log in to reply

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