其他分享
首页 > 其他分享> > Remove Duplicates From Linked List

Remove Duplicates From Linked List

作者:互联网

refer to: https://www.algoexpert.io/questions/Remove%20Duplicates%20From%20Linked%20List

Problem Statement

 

 Analysis

 

 Code

# This is an input class. Do not edit.
class LinkedList:
    def __init__(self, value):
        self.value = value
        self.next = None


def removeDuplicatesFromLinkedList(linkedList):
    currentNode = linkedList
    while currentNode is not None:
        nextDistinctNode = currentNode.next
        while nextDistinctNode is not None and nextDistinctNode.value == currentNode.value:
            nextDistinctNode = nextDistinctNode.next
            
        currentNode.next = nextDistinctNode# the first unique value(exclude the head node) found. let the head point to it
        currentNode = nextDistinctNode#update the current node
        
    return linkedList
        
            

Time and Space complexity

 

 

 

标签:None,currentNode,Duplicates,self,nextDistinctNode,List,value,next,Linked
来源: https://www.cnblogs.com/LilyLiya/p/14839683.html