LeetCode Remove Nth Node From End of List Solution Explained - Java

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


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

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

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

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

At 3:57, you said fast is at 4, I think this is incorrect. Fast should be at 3 because it starts from 0 which is the dummy head. At that moment, slow should be at the beginning which should be 0, not 1.

dengzhonghan
Автор

These leetcode problems really help a lot. We appreciate it!

amandapanda
Автор

i think if Nick explain it with 0 node in the video would be more understandable because the actual node in the solution is appended with a new node 0

khew
Автор

Hey Nick, I solved this problem with a similar method. But it was written there that we should do it in one pass. So, by having a fast and a slow pointer, arent we making 2 passes to the linked list?

varaddesai
Автор

0:14 - 0:17 '"And all that other crap"

anikethpaul
Автор

If n== length of list then we will get null pointer exception for your solution

shivarajbiradar
Автор

Hey why did you put 0th node in dummy node why not start the slow pointer and fast pointer from head instead??? Please explain

shivendrakumarverma
Автор

would it be possible to do this with a stack? if you pop all the nodes in, once node->next == nullptr, you could then pop the n times, store the toDelete->next as a temp, and the node left on the top would be the prev node which you can set next to delete's next? Or would this not actually work?

rebechkah
Автор

doesn't work when size of the list is same as n. simple if statement solves it but just pointing it out.

sunnychung
Автор

I have used a different method:
step1: Reverse the whole linked list.
step2: Traverse using count variable to print nth node.

soumyadeepmitra
Автор

I understood the code, but can you please explain the logic(the reason behind doing it this way) in words. That would be really helpful.

tahseenrahman
Автор

can we use temp instead of dummy_node ?

tekken
Автор

What if the value one enters is the the value at the beginning

Shiroyashasama
Автор

the loop should run to n-1, not n+1. Try it with n+1 and see it failed on test data.

pmolchanov
Автор

premium problems on patreon? really...

LuisMorales-yxdi
Автор

how can u always get better than 100% of the solution ??

sahilbarua
Автор

I solved this by traversing the whole list and at each point, I appended the node to an array. At the end, you get a an array containing pointers to each node of the list, and I just fetched the (len(arr) - n)th node from the array and deleted it.
That's one pass and without using two pointers. Why doesn't anyone talk about this solution?

entropy