Remove Linked List Elements - LeetCode 203 - Java

Поделиться
HTML-код
  • Опубликовано: 19 сен 2024

Комментарии • 6

  • @ledues3336
    @ledues3336 2 года назад +2

    Nice stuff man!

  • @ramshakhalid5761
    @ramshakhalid5761 2 года назад +2

    Why can't we not just return head; at the end instead of dummy.next?

    • @LeetCodeUniversity
      @LeetCodeUniversity  2 года назад

      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!

    • @ramshakhalid5761
      @ramshakhalid5761 2 года назад +1

      @@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.

    • @LeetCodeUniversity
      @LeetCodeUniversity  2 года назад +1

      @@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!