Merge Two Sorted Lists - Leetcode 21 - Linked Lists (Python)

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

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

  • @GregHogg
    @GregHogg  5 месяцев назад +2

    Master Data Structures & Algorithms For FREE at AlgoMap.io!

  • @BilalTroll
    @BilalTroll 5 месяцев назад +18

    This is the only explanation that makes sense, I prefer this over the neetcode video.

    • @GregHogg
      @GregHogg  5 месяцев назад +1

      Glad to hear it!!

    • @Fam-m4i
      @Fam-m4i 4 месяца назад +7

      Neetcode sucks man . I get bored watching his videos

  • @christianjt7018
    @christianjt7018 5 месяцев назад +2

    Very clean solution, thanks a lot!

    • @GregHogg
      @GregHogg  5 месяцев назад

      Thank you!

  • @yvettcodes
    @yvettcodes 2 месяца назад

    your videos are always so clear and helpful! thank you!

  • @darshanamohanan6101
    @darshanamohanan6101 4 месяца назад +1

    Thank you so much.This was really easy to understand.

  • @itsurabhi506
    @itsurabhi506 6 месяцев назад

    loved the explanation
    i've watched other videos where they created a new list and just added the values in sorted order
    changing the pointers is what was asked here
    Thank you very much

    • @GregHogg
      @GregHogg  6 месяцев назад

      No problem!

  • @Everafterbreak_
    @Everafterbreak_ 4 месяца назад +1

    really good explanation bro!

  • @creatorsstudio9
    @creatorsstudio9 5 месяцев назад +1

    can't thank you enough gregg !!!!

  • @AmanjotSingh-rj7ox
    @AmanjotSingh-rj7ox 5 месяцев назад +2

    thanks greg, i was not able to understand how its O(1) space until i saw your whiteboarding

    • @abhishekgeorge8626
      @abhishekgeorge8626 4 месяца назад

      can u explain me who it is o(1) im also confused

  • @pound9799
    @pound9799 2 месяца назад +3

    HOW IS THAT AN EASY QUESTION

  • @akshatsingh9830
    @akshatsingh9830 Месяц назад

    a issue which might be either me or bcom someone elses problem
    in ur c++ solution : correc the dummy node initialization ListNode*dummy = new ListNode(0) , this works everytime and doesnt produces error

  • @prathameshpatankar1864
    @prathameshpatankar1864 9 месяцев назад

    You made it easy to understand. Nicely explained.

    • @GregHogg
      @GregHogg  9 месяцев назад

      Glad to hear it!

  • @mroafish
    @mroafish 3 месяца назад +1

    What would a solution look like if we were asked to create a new node and then add it to our linked list? I am trying to implement that but i am struggling

    • @chuckyyys
      @chuckyyys 2 месяца назад

      def mergeTwoLists(self, list1, list2):
      cur1, cur2 = list1, list2
      # dummy node
      cur3 = l3 = ListNode()
      while(cur1 and cur2):
      # link current (of result list) to the new node
      cur3.next = ListNode()
      # move current to the new node
      cur3 = cur3.next
      # compare values
      if (cur1.val

  • @软件实验室
    @软件实验室 8 месяцев назад

    Really clear explanation, thank you so much! keep up the good work

    • @GregHogg
      @GregHogg  8 месяцев назад

      Very glad to hear it! Thanks so much :)

  • @cs_peter_lorenz
    @cs_peter_lorenz Месяц назад

    Hi Greg, thanks again for the nice explanation. However, I cannot fully understand this:
    d = cur
    cur.next = list1
    cur = list1
    Why the same time list1. Do you have some basics elsewhere?

  • @samfromuk796
    @samfromuk796 7 месяцев назад

    Love the explanation

  • @ECO720Hunter
    @ECO720Hunter 7 месяцев назад

    Thank you for the explanation. Very clear and neat. I'm a python-virgin and have two trivial questions
    1. how do you test the code? I've written a code and test it on leetcode and it's fine but when running on python, I can't test it and got error!
    2. Why do you insert # behind ListNode class? if it is excluded from the code how does the remaining part of the code work?

    • @GregHogg
      @GregHogg  7 месяцев назад +1

      Good question. Basically leetcode puts the class in a hashtag for readability. But the class is actually necessary. It's leetcode being weird

  • @AhmedElAlaoui-kb3xi
    @AhmedElAlaoui-kb3xi 23 дня назад

    Helpful :)

  • @tayyabkhan1139
    @tayyabkhan1139 3 месяца назад

    i am getting tle error

  • @stringjourney
    @stringjourney 8 месяцев назад

    Crisp and clear

    • @GregHogg
      @GregHogg  8 месяцев назад

      Super glad to hear it!!

  • @davea136
    @davea136 5 месяцев назад

    MergeSort, essentially.