LeetCode 83. Remove Duplicates from Sorted List Solution Explained - Java

preview_player
Показать описание


Preparing For Your Coding Interviews? Use These Resources
————————————————————

Other Social Media
----------------------------------------------

Show Support
------------------------------------------------------------------------------

#coding #programming #softwareengineering
Рекомендации по теме
Комментарии
Автор

If any one is confused in line 19, why he returned head rather then current_node.

Initially current pointer and head are pointing the same first element.
Inside while loop current pointer keep incrementing and keep modifying the original link list till it reaches last element.

After completion of while loop, current pointer is pointing to the last element of modified list.
But the head is still pointing to the first element of modified list. That's why he returned head

hariomgupta
Автор

A node is deleted by dereferencing it and then gets garbage collected.

SK-ybbx
Автор

Just Nick White casually destroying our self-esteem!!😂😂

tasneemayham
Автор

For those who are confused about the necessity of creating the "current_node": in the code you have to assign the "current_node" to the next ones, so the "current_node" is no longer the head node which we are supposed to return in order to submit the entire edited node list. If you try to return the "current_node" instead of the head, you will realize that it only returns the last element. That is because you have assigned the last element to the "current_node" in your code.

halitozgur
Автор

Remove Duplicates from Sorted List II is more trickier. Can you make a video? I think it is more likely to appear on interview than this problem.

CODINC
Автор

I think in cpp we would have to manually delete the node

nikunjkhakhkhar
Автор

This question is very ambiguous because they never stated that there will be at most 1 duplicate. I was trying to account for ALL possible duplicates (2, 3, 4, 5, etc.)

dion
Автор

Can you explain plz why we returning the head at the end ? We didnt change the actual head at all we did things only to current_node

alisherkholmirzaev
Автор

so current_node is not a copy of head.... anything change in current_node will affect head 's LinkedList

leomonz
Автор

can you please help me, as you a making changes in currentNode, but at the end you return the head why???
please help me to understand why

ASIFALI-gnpj
Автор

can't we just use the filter to filter all the duplicates rather then using the generator concepts

OUSSAMA-obdk
Автор

why it will be wrong if i only add while(current->next!=NULL)

parthdevbundela
Автор

Dude I'm so not understanding how changing the currentNode will also change head node. Why are we returning head ? How did the change occur? I'm slow.

sauravVocals
Автор

Free the memory before assigment : c->next

Ankushbindlish