Time 0(n) solution rejected


Says time limit exceeded


Can you kindly paste your code/logic here ?


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)
        nodes[currNode.val] = 1
        prevNode = currNode
        currNode = currNode.next
    return A
def removeNode(self, prevNode, currNode):
    nextNode = currNode.next
    prevNode.next = nextNode
    return nextNode