Question d’entretien chez Goldman Sachs

How to remove a node from a singly-linked list when only given the pointer to the node

Réponses aux questions d'entretien

Utilisateur anonyme

1 sept. 2010

thisNode.data = thisNode.next.data temporaryNode = thisNode.next.next delete thisNode.next thisNode.next = temporaryNode

13

Utilisateur anonyme

17 mars 2011

Milly: jobseeker is right in that you don't delete the "node to be deleted". You delete the node that FOLLOWS the "node to be deleted", only after swapping the values of the two.

2

Utilisateur anonyme

25 oct. 2010

Milly, jobseeker's assumption is reasonable, we should not delete the node before removing it from the list (if it was created by the list)

1

Utilisateur anonyme

21 oct. 2010

The post by "jobseeker" assumes that we know the node BEFORE the node to be deleted. This assumption is not consistent with the problem definition, but makes it solvable.

2

Utilisateur anonyme

25 nov. 2019

node = node.next;

Utilisateur anonyme

25 nov. 2019

node.val = node.next.val; node.next = node.next.next;

Utilisateur anonyme

8 mars 2016

node ->val=node->next->val; node ->next=node->next->next;

1

Utilisateur anonyme

31 juil. 2010

You have to use some pointer/memory trickery