Time 0(n) solution rejected


#1

Says time limit exceeded


#2

Can you kindly paste your code/logic here ?


#3

Same here, my solution was also rejected. Is it because it’s a Python answer?

class Solution:
# @param A : head node of linked list
# @return the head node in the linked list
def deleteDuplicates(self, A):
    if A == None or A.next == None:
        return A
    
    nodes = {}
    currNode = A
    prevNode = None
    while currNode is not None:
        if currNode.val in nodes.keys():
            currNode = self.removeNode(prevNode, currNode)
            continue
        nodes[currNode.val] = 1
        prevNode = currNode
        currNode = currNode.next
    return A
    
def removeNode(self, prevNode, currNode):
    nextNode = currNode.next
    prevNode.next = nextNode
    return nextNode