🚀 neetcode.io/ - A better way to prepare for Coding Interviews
@oanamanaljav3 жыл бұрын
Seems like the code is not working. Showed me the wrong result when compile.
@e-raticartist Жыл бұрын
hearing "hey guys i'm still unemployed so let's solve a leetcode problem today" and knowing you became a software engineer at google is so real and inspiring bro, thanks
@alwin599510 ай бұрын
Bruh he left job at amazon, and decided to voluntarily be unemployed. Dude's been a genius all along.
@rohitkumarsinha8763 жыл бұрын
"hey guys i am still unemployed so lets solve a problem " this is savage bro
@farnazzinnah85413 жыл бұрын
he earns fro youtube tho
@samirpaul22 жыл бұрын
😂
@computergeek56572 жыл бұрын
KZbin hired him
@neerajmahapatra52392 жыл бұрын
Now he is at google
@omkarjadhav84822 жыл бұрын
💯😂
@chair_smesh2 жыл бұрын
I get so inspired/motivated when you mention unemployment in your old videos because of where you ended up
@smalldoggo37043 жыл бұрын
that intro hit me different
@NeetCode3 жыл бұрын
lol
@khouloudsaid24792 ай бұрын
hhhhhhhhhhh me too
@bigrat51012 жыл бұрын
"hey guys i am still unemployed so lets solve a problem " this one cracked me up because right now all your efforts paid off and look back, we all have been there..ah what a journey!!!
@mehmetnadi89302 жыл бұрын
I've been watching your solutions for a while now and I'm just so happy that I finally started to solve problems like the way you do. Thank you so much!!
@snoudoubts17452 жыл бұрын
That beginning took me by surprise, instantly made my evening better. Thanks
@syafzal2739 ай бұрын
Awesome, I love how you dealt with all the edge cases without cluttering the code
@anantmulchandani7092 жыл бұрын
Congratulations that you are now employed!! Happy for you!
@philhamlin79353 жыл бұрын
Excellent! Clear and plain explanations, and it's so much cleaner when hand mark-up is by pen instead of by mouse. :) This is linked in LeetCode as "optimized solution explained" on the problem itself, but it'd be faster to take: carry = val // 10 val = val % 10 ...and make it instead: carry = 1 val = val - 10 The modulus approach is fantastic for expanding our algorithm to support adding up three or more arrays, but in our use case carry will always be 0 or 1.
@stementhusiast8163 жыл бұрын
You would require 'if' statements. if val >= 10: carry = 1 val = val - 10 Which would reduce the elegance of code
@khatharrmalkavian33062 жыл бұрын
Nothing about this problem is elegant or worth optimization.
@Eftahhh4 жыл бұрын
So simple, thank you. I was casting the linked list values to strings and reversing them, then casting them back to ints and adding them... needless to say I was making spaghetti. Your example is very clean!
@prudvi013 жыл бұрын
lol that was my initial solution as well! got dirty real quick
@liferayasif93823 жыл бұрын
I did same, thanks
@UnknownSend3r3 жыл бұрын
@@prudvi01 I used an if statement inside a while loop, would that be wrong even if it works, if not what's wrong with it ? As in does the solution have to be a linked list.
@BromaniJones2 жыл бұрын
I did the same. I'm not convinved it's any worse than the solution presented in the video. looping through two linked lists (and a third for the output) is O(n) time complexity.
@gustavotelez97952 жыл бұрын
def addTwoNumbers(l1,l2): l1.reverse() l2.reverse() l1s= str(l1) l2s= str(l2) l1s= "".join(l1s) l2s= "".join(l2s) l1 = "" l2 = "" for i in range(1, len(l1s), 3): l1 +=l1s[i] for i in range(1, len(l2s), 3): l2 +=l2s[i] l1s=int(l1) l2s=int(l2) res=l1s+l2s res= str(res) res= list(res) res.reverse() return res
@passionatechristianworker6 ай бұрын
i'm amazed at your ability. it's the nuances in the code that's the hardest to figure out. kudos to you.
@anthonypeters17972 жыл бұрын
Couldn’t have solved this without you. Thank you so much
@alok74852 жыл бұрын
Can you please explain what will be the time complexity and space complexity for this piece of code in example?
@MrYosuko8 ай бұрын
The intro slapped me back into reality. As always, thanks for the awesome explanations 😄
@mu03253 жыл бұрын
I traversed through both linked list and got the actual numbers, added them, then created a linked list with the result's digits as nodes.
@inspisiavideos85423 жыл бұрын
hi, Please let me know. Why is the value divided by 10? I'm learning how to code and I don't know where he got the number 10? (on minute 7:29)
@danielwilczak78333 жыл бұрын
@@inspisiavideos8542 You divide by 10 so that you can add it to the next number which will be in the next 10's place. For example: if you took 25 + 26 if you add 5 + 6 and then divide by 10 you'll get 1. So i take my one and add it to the next 10's place which is 2 + 2 + 1 that i got from carrying the number which will total 51.
@inspisiavideos85423 жыл бұрын
@@danielwilczak7833 Thank you so much!!! I got an internship during this Summer as QA and just finished it but I asked for an extension and if I could get it this time as Dev. They said yes. I have coded before with courses on how to make websites but I have never done code questions. Basically this next week is my first week. It’s so hard to get a job so they told me that they don’t have entry level positions and senior positions are more than likely ending up on people who are already in the company. So basically I’m learning as much as I can during my spare time to then perhaps they let me stay after the internship extension ends by the end of the year.
@philhamlin79353 жыл бұрын
@@inspisiavideos8542 Congrats on your internship! Calling out 10 as a "magic number" is really great - bare numbers with no evident explanation can cause a lot of confusion in code, so 10 could be a constant called NUMBER_BASE since we're just using decimal notation here. For extra fun, make it not a constant, and adapt the algorithm to work in number bases other than 10!
@inspisiavideos85423 жыл бұрын
@@philhamlin7935 hey thanks! My internship was supposed to end in August but was extended to the end of December. I’ve been applying to other companies but nothing yet even though I have projects on my portfolio. My internship manager told me to stay alert when an opening occurs and apply. 2 positions opened and I applied there this week. Hopefully they’ll let me know and I be ready for a test code. The company has many teams so probably the person who sees my resume doesn’t know me yet.
@anamikaborah53938 ай бұрын
Love how you started the video! xD You made my life easier by posting these videos. Great work! :) :D
@raymondcordero9718 Жыл бұрын
By far the best explanation of this problem I’ve seen 👏 Thanks for sharing
@SweVillian-mt6nk8 ай бұрын
This intro make this video my favorite one 😂. Could be a useful cue to remember the solution in an interview even.
@MatthewPostrel11 ай бұрын
Explanation was crystal clear and helped me solve the problem super quick. Thanks!
@pratikshanaik4143 Жыл бұрын
Better explanation than the official solution explanation.
@nivethanyogarajah149327 күн бұрын
Legendary Introduction!
@techbrojoe3 жыл бұрын
Thanks for making this. Trying this problem is the first time I've ever tried using a Linked List, so this helped solidify the solution LeetCode provides.
@alok74852 жыл бұрын
Can you please explain what will be the time complexity and space complexity for this piece of code in example?
@passionatechristianworker6 ай бұрын
"you probably do but you might think you don't". Haha, thanks for the encouragement.
@__________________________69102 жыл бұрын
You are best. I always pause ads blocker for you.
@morenoh149 Жыл бұрын
its interesting how you build the answer after the dummy node and return the answer. Its not like the test cases can detect the dummy node
@whatdoiputhere50893 жыл бұрын
Dude, thankyou for this solutions. They are helping me alottttt! Also, if you could please make a video on intersection of two linked lists
@alok74852 жыл бұрын
Can you please explain what will be the time complexity and space complexity for this piece of code in example?
@siruitao2 жыл бұрын
Haha, now you are so employed! Thanks for these great contents!
@oooo-rc2yf3 жыл бұрын
If the person teaching these is unemployed what chances do we have...
@fernandoplak692520 күн бұрын
rofl
@shooby11710 ай бұрын
"hey guys i am still unemployed so lets solve a problem" mans representing his entire audience 😂😂😂
@jaisinha1378 Жыл бұрын
Only Platform I choose for any coding explanation
@bulkan.evcimen11 ай бұрын
this explanation is much better than the leetcode editorial
@tsunningwah347110 ай бұрын
can anyone tell me why we're returning the dummy.next and not dummy itself? wont we be able to access every other element if we just return dummy?
@vinaykumar-gg4mx3 жыл бұрын
A complete beginner question, how to call and declare the inputs for addTwoNumbers function, just to test the program !
@rotors_taker_0h Жыл бұрын
For some reason it was extremely easy problem for me, first time that I just saw the solution instantly in full (unlike all “easy” ones before) and was so surprised of everyone’s animosity to this problem, lol.
@ishaanbhalla3962 жыл бұрын
Man I was super stressed out solving these leetcodes, but the " Hey I am still unemployed" made my day! LMAO
@EranM5 ай бұрын
"Hey guys, I'm still unemployed.." Many kisses for you neet! you make me laugh.. And relax... To the best ASMR Channel OUT-THERE!!!! Please go back to this microphone and keyboard, and relaxed voice!!!!!!!!! damn I enjoy this
@serpent27765 ай бұрын
I am so happy that LC decided to give us reversed lists for this problem
@Silver-lu1dt9 ай бұрын
This is the way I learnt about pointer, I can't believe it
@pahul79 Жыл бұрын
thanks for making these videos man, your awesome
@miyamotomusashi45562 жыл бұрын
Wow, this was very well explained!
@TheEllod2 жыл бұрын
nulll and zero are different, you should instead append the while statement to while l1 or l2 or carry>0
@jaspreetsahota184010 ай бұрын
In python, 0 evaluates to its Boolean value (False) in a conditional clause. So it's fine to just have carry.
@TheEllod10 ай бұрын
@jaspreetsahota1840 good to know!
@bizdep62373 жыл бұрын
@NeetCode Could you please explain the time complexity of the problems you solve? It will be really useful for us.
@wlockuz44672 жыл бұрын
For this one it should be O(n + m), where n is length of first linked list and m is length of second linked list.
@predatorgaming8952 жыл бұрын
@@wlockuz4467 no bro... Either O(n) or O(n+1) where n is the length of linked list which has more nodes
@alok74852 жыл бұрын
Can you please explain what will be the time complexity and space complexity for this piece of code in example?
@likkiii07 Жыл бұрын
@@alok7485 Time complexity will be O(max(n, m)) and Space complexity will be O(max(m,n))
@DracosThorne Жыл бұрын
NC: You do probably remember how to add two numbers together Me: You severely overestimate my abilities
@heyyy_rosa45203 жыл бұрын
This solution is so elegant.
@tomonkysinatree4 ай бұрын
I was really close to the solution on this one. I had an extra node at the end because I was creating my node in cur instead of cur.next(). Slowly getting better at these
@stylisgames4 ай бұрын
I was able to solve this one, but did not think of dividing the current sum by 10 and using Math.floor() to get the first digit as the carry number, and then using modulo to get the second number aka the current sum. So darn clever! Instead I converted the sum to a string and grabbed the values by index.
@shantipriya3705 ай бұрын
wonderful explanation
@ahmetrauf219510 ай бұрын
great explanation!
@qazianeel2 жыл бұрын
I have interview on 21st March, there is no way I am gonna pass :( This level of programming is going above my head
@supriyamanna7152 жыл бұрын
kaya hua? Pass kiya tumne?
@alok74852 жыл бұрын
Did u pass?
@Davidsito44 Жыл бұрын
how did it goes?
@adityadixit14042 жыл бұрын
To deal with edge case just before . return dummy.next write If carry==1: cur.next= ListNode (1)
@MrBear-no7iq3 жыл бұрын
Thank you !! I finally understand it now
@ozgeylmaz86852 жыл бұрын
Great video and great channel I am very excited to discover this channel I hope I benefit from this channel a lot .Thanks a lot😊
@NeilSharma-u5nАй бұрын
The first medium LL problem I could solve with optimized code.
@maharshibiswas3557 Жыл бұрын
Inspirational first line
@Moon-li9ki5 ай бұрын
I'm really proud of mylsef. I finally managed to solve a medium problem by myself, although my solution was slow as hell xd
@InfoBuzz11302 жыл бұрын
LOVE you my GURU your awesome!!!
@wlcheng2 жыл бұрын
I am very happy for you that you are employed at Google now. 😀
@m0sh310 ай бұрын
This code only passes 1365/1568 test cases. Update needed.
@ABHINAVKUMAR-pl4iw2 жыл бұрын
you are the legend
@alicia81702 жыл бұрын
At the start of the loop cur = dummy. On the first iteration you are assigning cur.next (aka dummy.next) with the first digit of the solution. So now dummy.next equals the head node of the solution so at the end we return dummy.next. dummy.next will always point to this head node no matter what cur gets changed to.
@alicia81702 жыл бұрын
I quote your response to ask the question further. As I understand, cur = dummy means let cur be dummy, but they are not the same one. I still don't understand whey cur.next will change dummy.next. Did I miss anything? Thank you so much!
@oliverbao49259 ай бұрын
@@alicia8170 hi yeah i'm wondering the same thing - although we didn't reference dummy at all or change its value, it gets built on as we change cur and cur.next - is this a python binding or pointer issue?
@dreamingaparisdream31783 жыл бұрын
I got some errors when I ran your exact code. Is your solution missing the case when the highest position creates a carry of 1?
@yinglll74113 жыл бұрын
you might have missed the "+ carry" bit when summing up the "val"
@dorb1337 Жыл бұрын
while l1 or l1 or carry:
@noumaaaan3 жыл бұрын
A little confused,how are we adding in reverse order? we're just adding v1 and v2 which is normal addition isn't it?
@khatharrmalkavian33062 жыл бұрын
The digits are in reverse order.
@michaelwilliams8986Ай бұрын
I'm getting memory limit exceeded. Did something change on Leetcode's end?
@dr.merlot15323 жыл бұрын
My sentiments exactly. If NeetCode is unemployed, what chances do we have...
@NeetCode3 жыл бұрын
Well.. not anymore :p
@dr.merlot15323 жыл бұрын
@@NeetCode In my heart and mind, you are still unemployed.
@DanielSmith-uj7rr3 жыл бұрын
BRO! UNIQUE..!! "Hey Guys, I am still UNEMPLOYED so let's solve a problem!" Lmao!😂
@bilal2.0422 жыл бұрын
thank you for the explaination :)
@computergeek56572 жыл бұрын
KZbin hired u👍
@raviy10 Жыл бұрын
Thank you !!!
@tsunningwah347110 ай бұрын
can anyone tell me why we're returning the dummy.next and not dummy itself? wont we be able to access every other element if we just return dummy?
@programlamaicin2 жыл бұрын
Thank you for clean explanation. When 2 ListNode has different sizes you better check for l1 is None or not otherwise you'll have an runtime error. v1 = l1.val if l1 is not None and l1.val else 0 v2 = l2.val if l2 is not None and l2.val else 0
@plankton3832 жыл бұрын
He does that already. “if l” is short for “if l is not None”.
@NabeelGm2 жыл бұрын
Can someone explain why we don't use the first dummy list node? Why not use dummy.val and assign?
@gimmeadollr Жыл бұрын
I think it's because we want the logic to be "the next thing is ___" for every iteration, so we make a dummy list node and immediately start with our logic (the next thing for the dummy node is ___). If you use dummy.val, you have the first step do the logic of "the value here is ___" and then the later steps are "the next thing is ___" which is more inconvenient to write. That's how I thought of it, not sure if that's the right way to think about it.
@yuriish7570 Жыл бұрын
I cant figure out how does cur work. If I print id(cur) == id(dummy) it's true, but if i print cur and dummy inside or after while cycle the output is different. Tell me please what's going on or What should I google to clarify that ?
@aumrudhlalkumartj19482 жыл бұрын
Thanks
@sangpark7656 Жыл бұрын
what's the function of next and val do?
@rohanmahajan63338 ай бұрын
so do we have a first node that is just null in all of these
@symbol7672 жыл бұрын
0:00 Lol now you're at Google. Here I am just trying to get Amazon or Microsoft now. Awesome solution, I managed to actually solve this one myself but wanted to see your way of doing it, much cleaner. Thank you! Liked!
@guyfieri4605 Жыл бұрын
I don't understand what's going on with carry. Wouldn't always be a left over number there by the time two get to the second digit in the list nodes. First time through: val = 2 + 5 + 0 carry = 7 // 10 Doesn't that leave carry as .7 when we get to the next digits? I'm very confused.
@aiml66_bangerashashankchan81 Жыл бұрын
In Python, we can perform floor division (also sometimes known as integer division) using the // operator. This operator will divide the first argument by the second and round the result down to the nearest whole number So, 7 // 10 = 0
@sanooosai Жыл бұрын
great thank you
@infos53192 жыл бұрын
Can you explain how can I call the l1 and l2 listnodes in the addtwonumber function to test?
@crosswalker452 жыл бұрын
it's a bit compicated to explain it in words. I would rather suggest you to watch the videos on how to create linklist object and other related problems ( which aren't directly given into the function like this leetcode problem)
@mugilmithran69552 жыл бұрын
@@crosswalker45 hi, thanks a lot man.
@techenthusiast39662 жыл бұрын
Here after when you got job in Google.... congratulations:)
@asmahamdym Жыл бұрын
Wow this is so clean✅✅ I brute- forced my way to this problem and it's functional but really ugly 😀
@iambdot Жыл бұрын
Stupid question but how does "dummy" get updated when all code changes are done to "cur"?
@chillcoder Жыл бұрын
Both dummy and cur are both pointers to the same list, but serve different purposes: We are using dummy to point to the start of the list and cur will be used to add additional nodes + move to the latest node in the list.
@IvanRadonjic-j9f9 ай бұрын
# Definition for singly-linked list. # class ListNode(object): # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution(object): def addTwoNumbers(self, l1, l2): """ :type l1: ListNode :type l2: ListNode :rtype: ListNode """ def reverse_in_place(head): before = None temp = head while temp is not None: after = temp.next temp.next = before #flip pointer before = temp #cross 'gap' temp = after # move temp over return before #before is the new head of reversed LL l1 = reverse_in_place(l1) l2 = reverse_in_place(l2) temp_l1 = l1 l1_val = "" temp_l2 = l2 l2_val = "" while temp_l1 is not None: l1_val += str(temp_l1.val) temp_l1 = temp_l1.next while temp_l2 is not None: l2_val += str(temp_l2.val) temp_l2 = temp_l2.next total = int(l1_val) + int(l2_val) total = str(total) temp_out = ListNode(int(total[0])) new_LL = temp_out for i in range(1, len(total)): if temp_out.next is None: temp_out.next = ListNode(int(total[i])) temp_out = temp_out.next new_LL = reverse_in_place(new_LL) return new_LL This is my brute force method for this problem but i dont think its THAT bad on time and space complexity LOL what do you guys thing
@heyquantboy3 жыл бұрын
Beginner question- I wanted to build test cases before diving in. I went off on a tangent to construct ListNode instances- which I needed as inputs to LeetCode's provided addTwoNumbers interface. I prepared all my tests before even thinking about the solution. Is this wrong? I don't see anyone doing this. Is this wrong or shouldn't we do TDD?
@mrunfunny3 жыл бұрын
This is a perfectly valid strategy but it's time consuming and hence not popular in CP community.
@badachoi68822 жыл бұрын
I did 'print(Solution().addTwoNumbers(l1,l2))' and got error "list object has no attribute 'val'... how do I fix it?
@sajithraj3832 жыл бұрын
Can Some please explain why the dummy is still getting updated when after the first iteration cur is updated to a different object. newNode = ListNode(columnSum % 10) curr.next = newNode curr = newNode
@robwalsh38582 жыл бұрын
At the start of the loop cur = dummy. On the first iteration you are assigning cur.next (aka dummy.next) with the first digit of the solution. So now dummy.next equals the head node of the solution so at the end we return dummy.next. dummy.next will always point to this head node no matter what cur gets changed to.
@ai4sme2 жыл бұрын
Hi Sajith, Here a good explanation: stackoverflow.com/questions/58759348/when-does-a-pointer-to-a-linked-list-change-the-actual-list
@drainedzombie25089 ай бұрын
@@ai4sme Thanks for this. TIL python variables are essentially references/pointers to objects i.e. class instances.
@TobiasLange-n5c2 ай бұрын
Why do you write in the while loop just "l1 or l2 or carry"
@mojajojajo3 жыл бұрын
Why are these things so difficult 😣?
@02devavratkumarmahato113 ай бұрын
Why can't we just return cur.next ??
@02devavratkumarmahato113 ай бұрын
I mean the cur is pointing to dummy right? So just print it right idk if I'm right
@AdityaRaut-l6p2 ай бұрын
i think that will skip first value
@indhumathi5846 Жыл бұрын
understood
@giggity302 жыл бұрын
"I am still unemployed" Not anymore!
@nerdclapper1983 Жыл бұрын
There is a VERY simple solution. Simple go through both lists and for each one create a string with the values. Then reverse both strings, convert them to int and add them together. Then convert that to a string and go through each char and create a new Node in the new LL, still O(n) def addTwoNumbers(l1: ListNode, l2: ListNode) -> ListNode: # treat them as string and reverse them s1 = "" cur = l1 while cur: s1 += str(cur.val) cur = cur.next s2 = "" cur = l2 while cur: s2 += str(cur.val) cur = cur.next s1 = s1[::-1] s2 = s2[::-1] # Calculate the new number res_string = str(int(s1) + int(s2)) # Reverse it res_string = res_string[::-1] # Create the new LinkedList dummy = ListNode(-1) prev = dummy for char in res_string: cur = ListNode(int(char)) prev.next = cur prev = cur return dummy.next
@Jambajakumba Жыл бұрын
I went for a similar approach. Simplest to think about. And linear time as well. I would advice to make one long iteration for both l1 and l2, using l1 or l2 not being None. Good job!
@piyusharyaprakash4365 Жыл бұрын
you don't need to reverse the string if you do it like this s1 = str(cur.val) + s1
@hwang160711 ай бұрын
@@piyusharyaprakash4365 can you explain this
@lifeofme3172 Жыл бұрын
could have reduced these statements within single block, otherwise awesome explanation thank you if(l1 != null){ v1 = l1.val; l1 = l1.next; } if(l2 != null){ v2 = l2.val; l2 = l2.next; }
@ABagOfLag7 ай бұрын
i solved it using more memory but it eliminates thinking about edge cases: nums1, nums2 = [], [] cur = l1 while cur: nums1.append(cur.val) cur = cur.next cur = l2 while cur: nums2.append(cur.val) cur = cur.next nums1 = nums1[::-1] nums2 = nums2[::-1] num1 = int(''.join(map(str, nums1))) num2 = int(''.join(map(str, nums2))) vals = [] number = str(num1 + num2) for c in number: vals.append(int(c)) dummy = ListNode(0) cur = dummy while vals: cur.next = ListNode(vals.pop()) cur = cur.next return dummy.next
@JC-yo5hu Жыл бұрын
When was dummy head ever updated in the code? Please help!
@neelshah1617 Жыл бұрын
Thank you for a quick solution! However, it is not space optimized as per the requirement: Ignoring the allocation of a new linked list, try to use constant memory when solving it. Would be better to add summation digits in longer LL.
@alyahmed9925 Жыл бұрын
Can someone explain the dummy listnode and how changing in cur changes dummy?
@MrRedHairedShanks Жыл бұрын
@yuushamenma21304 жыл бұрын
The only part I don't understand about this, and it's a pretty stupid question is: why do we return dummy.next? I assumed dummy.next would refer only to the next node in the linked list and not the whole list.
@bonfire622924 жыл бұрын
The reason is because he is modifying the .next node in the array be default, so we're just not modifying the original node. Thus we return the .next node as the "beginning" of the list.
@hariprasadg1233 жыл бұрын
@@bonfire62292 but where is the dummy.next getting assigned? Initially a dummy node is created and it is assigned to cur. Only cur is being updated right?
@dweebosupremo59043 жыл бұрын
@@hariprasadg123 I could be wrong but i think cur and dummy both point at the same object. If you've seen a binary tree inversion problem solution, it's the same reason you would need to create a temp before setting left = right and right = left. I could be wrong though.
@ivanz49323 жыл бұрын
In the LeetCode compiler, there is some instruction: """ :type l1: ListNode :type l2: ListNode :rtype: ListNode """ This indicates you only need to return the first node of the output. Of course there are some extra codes in the background to initiate two input lists and print the output list, but LeetCode already took care of that. It could look like this: l1 = ListNode(2) l1_2 = ListNode(4) l1_3 = ListNode(3) l2 = ListNode(5) l2_2 = ListNode(6) l2_3 = ListNode(4) l1.next = l1_2 l1_2.next = l1_3 l2.next = l2_2 l2_2.next = l2_3 final1 = Solution().addTwoNumbers(l1,l2) final2 = final1.next final3 = final2.next print [final1.val, final2.val, final3.val]
@bizdep62373 жыл бұрын
@@ivanz4932 Where do you see the leetcode compiler instructions in the question? I don't find this part where it says that the return type is just one node. But it makes sense now that why the output of the program returns dummy.next. Thanks for explaining this part with much needed details.
@tirasjeffrey200211 ай бұрын
can anyone tell me why we're returning the dummy.next and not dummy itself? wont we be able to access every other element if we just return dummy?
@tsunningwah347110 ай бұрын
yes i have the same question too. I thought dummy itself is the real list
@m0sh310 ай бұрын
@@tsunningwah3471 dummy is initialized to default value of 0 for the purpose of having an initial node to attach everything else to. dummy.next is the real start of the summed list.
@tsunningwah347110 ай бұрын
@@m0sh3 thanks got it!
@theunderhook99132 жыл бұрын
Why can;t we simply reverse two lists first, sum them and then reverse an output?