Lets say that you have [7] and we want to remove 7. The output should be []. Now, when we use dummy node and we remove 7 (which in this case is the head) the dummy.next will now point to null which is what we want, where the head variable is still pointing to the node containing 7. Hope this helps!
@@LeetCodeUniversity That makes a lot of sense. Thank you! I found your channel a few hours ago and I've watched 5 videos so far, and I wanted to mention that I absolutely love the 5-step approach you have to each problem. It really helps to visualize the data structure and understand every step of the algorithm. Keep up the good work.
Nice stuff man!
Thank you so much, glad I helped!
Why can't we not just return head; at the end instead of dummy.next?
Lets say that you have [7] and we want to remove 7. The output should be []. Now, when we use dummy node and we remove 7 (which in this case is the head) the dummy.next will now point to null which is what we want, where the head variable is still pointing to the node containing 7. Hope this helps!
@@LeetCodeUniversity That makes a lot of sense. Thank you! I found your channel a few hours ago and I've watched 5 videos so far, and I wanted to mention that I absolutely love the 5-step approach you have to each problem. It really helps to visualize the data structure and understand every step of the algorithm. Keep up the good work.
@@ramshakhalid5761 Thank you so much Ramsha for these kind words. They really mean a lot. I am so grateful that you are finding value in the videos!