Leetcode 2. Add Two Numbers | Add digits of two linked lists and return their sum | Linked List

  Рет қаралды 89,428

Code with Alisha

Code with Alisha

Күн бұрын

Пікірлер: 110
8 ай бұрын
You can avoid some code duplication by doing like this: public ListNode addTwoNumbers(ListNode l1, ListNode l2) { ListNode l3 = new ListNode(-1); ListNode l3Head = l3; int carry = 0; while (l1 != null || l2 != null){ int l1Val = 0; if (l1 != null) { l1Val = l1.val; l1 = l1.next; } int l2Val = 0; if (l2 != null){ l2Val = l2.val; l2 = l2.next; } int value = l1Val + l2Val + carry; l3.next = new ListNode(value % 10); carry = value / 10; l3 = l3.next; } if (carry != 0){ l3.next = new ListNode(carry); } return l3Head.next; }
@lifekool5838
@lifekool5838 2 жыл бұрын
in depth knowledge of how to solve a particular problem and how to take care of edge cases. Best explanation ever
@ParthG-vi4ml
@ParthG-vi4ml 10 ай бұрын
really 😃 breaking down the problem into smaller chunks & solving every chunk 1 by 1 is the best thing of this channel.
@DG_Theniel
@DG_Theniel 5 ай бұрын
been looking several videos of this problem. This is by far the best explaination video I have ever seen. Finally someone who can shove down information in my brain. Thank you
@RashidIqbal-i9i
@RashidIqbal-i9i Жыл бұрын
I see many videos, but you explain very well. Best explanation and easy to understand.
@SleepyBaseball-ts7se
@SleepyBaseball-ts7se 10 ай бұрын
Ma'am, I'm working with java but I got complete logic of the code Hats off to you Ma'am
@viencong
@viencong 2 жыл бұрын
100 point for you. Love you very much for explain so eassy to understand
@rakeshruler2524
@rakeshruler2524 2 жыл бұрын
You explained it in student way thank you for the simple logic ! A lots of love
@MdineshKumar-gp9wg
@MdineshKumar-gp9wg 2 жыл бұрын
i started coding last few weeks.your viedoes was so helpful to me .thank you
@probabilitycodingisfunis1
@probabilitycodingisfunis1 2 жыл бұрын
ListNode* l3 = new ListNode(0); int carry =0; ListNode* head = l3; while(l1 && l2) { int value = l1->val+l2->val+carry; carry = value/10; l3->next = new ListNode(value%10); l3 = l3->next; l1 = l1->next; l2 = l2->next; } while(l1) { int value = l1->val+carry; carry = value/10; l3->next = new ListNode(value%10); l3 = l3->next; l1 = l1->next; } while(l2) { int value = l2->val+carry; carry = value/10; l3->next = new ListNode(value%10); l3 = l3->next; l2 = l2->next; } if(carry) { l3 ->next = new ListNode(carry); } return head->next;
@saijeswanth6673
@saijeswanth6673 Жыл бұрын
Is this Code is working in leetcode. It shows L3 statements at all cases getting error. L3 Statement is not a statement. Can anyone please help for this issue. Why it is coming
@shubhamkate7849
@shubhamkate7849 Жыл бұрын
@@saijeswanth6673 if you working in java use ListNode l3 = new ListNode (0);
@shubhamkate7849
@shubhamkate7849 Жыл бұрын
@@saijeswanth6673 class Solution { public ListNode addTwoNumbers(ListNode l1, ListNode l2) { ListNode l3= new ListNode(0); ListNode newhead=l3; int carry=0; while(l1!=null && l2!=null){ int result= l1.val+l2.val+carry; carry=result/10; l3.next= new ListNode(result%10); l3=l3.next; l1=l1.next; l2=l2.next; } while(l1!=null){ int result= l1.val+carry; carry=result/10; l3.next= new ListNode(result%10); l3=l3.next; l1=l1.next; } while(l2!=null){ int result= l2.val+carry; carry=result/10; l3.next= new ListNode(result%10); l3=l3.next; l2=l2.next; } if(carry!=0){ l3.next= new ListNode(carry); } return newhead.next; } }
@ashishshetty4363
@ashishshetty4363 9 ай бұрын
@@shubhamkate7849 can anyone explain why her code is not working
@namrathas5804
@namrathas5804 Жыл бұрын
Thank you so much Alisha, your code and explanation was so easy to understand.
@nakuldeshmukh7901
@nakuldeshmukh7901 2 жыл бұрын
best explanation of this problem on yt. Very simple to understand .Kudos!
@abhi_jit_tripathy
@abhi_jit_tripathy Жыл бұрын
thank you so much for this great explanation....I soled this problem in 3 different ways but some test cases didn't ran...When i saw ur explanation it was super easy...thanks a lot for this........
@honey6567
@honey6567 2 жыл бұрын
VERY GOOD EXPLANATION KEEP MORE MORE VIDEOS IN LEET CODE THANKS
@negi-ji
@negi-ji Жыл бұрын
thankew thankew thankew ! itna ache se samjhane ke liye. i was stuck in this problem because of the corner cases. Baaki videos se kuch khaas samaj nahi aya but with this video i got it all in one go! replay bhi nahi karna pada and i wrote it in java. once again thanking you🫂... bhagwan aapko ek world tour gift kar de meri taraf se🙏
@darshanpancholi8746
@darshanpancholi8746 10 ай бұрын
just loved the way you explained....❤❤
@himanshugupta3699
@himanshugupta3699 2 жыл бұрын
You have no idea how confused I was in this..Thankyou for making this video
@zeyadalbadawy2245
@zeyadalbadawy2245 Жыл бұрын
Alish , your explaination is unparallel !!
@imran3509
@imran3509 Жыл бұрын
Gajab bhai mast samjhaya
@hemantdixit4058
@hemantdixit4058 2 жыл бұрын
so much clarity in your explanation, amazing
@Modern_Monk8926
@Modern_Monk8926 2 ай бұрын
You know what you just gained one more subscriber😊😊 by the way thanks for the explanation
@syedmunawar9809
@syedmunawar9809 2 жыл бұрын
I am begining to code and your video is helpful
@muhsinmansooriee_0017
@muhsinmansooriee_0017 2 жыл бұрын
this is the first video on youtube that truly made me feel to subscribe. Thanks a lot.
@probabilitycodingisfunis1
@probabilitycodingisfunis1 2 жыл бұрын
Thank you so much Muhsin
@soumyadas900
@soumyadas900 2 жыл бұрын
ju ke ho kya ?
@muhsinmansooriee_0017
@muhsinmansooriee_0017 2 жыл бұрын
@@soumyadas900 haan 🥲
@TeachingCodes
@TeachingCodes Жыл бұрын
Nice Explanation, Keep it up
@cse0798
@cse0798 2 жыл бұрын
thanku so much di I understand 100 percent of your explanation with clarity because you explain so good keep it up di and help all
@_VISHALKUMAR-du2nu
@_VISHALKUMAR-du2nu 10 ай бұрын
superb teaching skill
@alastairhewitt380
@alastairhewitt380 Жыл бұрын
One of the best explanations I've seen. However, what is still throwing me off with LeetCode's solution was that they had l3 = head rather than head = l3 as you have here and I have been hung up on it for a while. I would appreciate it a lot if you could please help me understand why the order of the assignment doesn't seem to matter 🙏🙏🙏
@PranavKamathe
@PranavKamathe 4 ай бұрын
Thank you Didi...!!✨
@Khabib901
@Khabib901 Жыл бұрын
Great Explanation
@anikmahmud1748
@anikmahmud1748 2 жыл бұрын
carry on sister.your explanation is better than any other explanation❤❤❤❤❤
@florianion4633
@florianion4633 2 жыл бұрын
omg so much work put into this channel. thx for help and great work
@AbhiWarrior122
@AbhiWarrior122 11 ай бұрын
nice explaination Didi it really helps
@tamzeedahmed1536
@tamzeedahmed1536 11 ай бұрын
Great explanation!!
@HARIHARAKRA
@HARIHARAKRA 2 жыл бұрын
Your explaination is soothing..keep going mam
@tarushidubey2973
@tarushidubey2973 Жыл бұрын
very well explained di
@sharadkumar6658
@sharadkumar6658 2 жыл бұрын
Nice mam. It was really good.😇😇
@34adnanali26
@34adnanali26 Күн бұрын
great
@adyamansingh2983
@adyamansingh2983 Жыл бұрын
amazing explaination
@hameedmulani21
@hameedmulani21 2 жыл бұрын
Best explanation
@mukulyadav655
@mukulyadav655 Жыл бұрын
your codes are really helpful thanks
@anshulvats1570
@anshulvats1570 2 жыл бұрын
Arey wah. Maine bilkul aisa hi code likha tha java mein bus ye extra while loops nhi likhey they (when length of lists are not same) hmmm... Very nice explanation @Alisha Keep growing
@probabilitycodingisfunis1
@probabilitycodingisfunis1 2 жыл бұрын
Awesome! Keep practising Anshul !
@17.shubhamashish27
@17.shubhamashish27 7 ай бұрын
nice explaination
@KaushalSharma-yo2yu
@KaushalSharma-yo2yu Жыл бұрын
perfect example of beauty with brain
@KartikSharma-yi4vg
@KartikSharma-yi4vg Жыл бұрын
Very Good Video
@luckylam1181
@luckylam1181 Жыл бұрын
Thanks for the great explanation!
@Coding-Just
@Coding-Just Жыл бұрын
Thanks a lot 👍👍👍
@sayankarmakar13
@sayankarmakar13 8 ай бұрын
Appreciated ❤
@vitaminprotein2217
@vitaminprotein2217 2 жыл бұрын
A hardstuck will always understand from you :D
@projectsdb4034
@projectsdb4034 Жыл бұрын
Thanks Great Logic
@Basantkumarr
@Basantkumarr Жыл бұрын
Amazing explanation 😊 please make more videos
@adarshkumargupta.
@adarshkumargupta. 2 жыл бұрын
vey nice explanation
@mikedelta658
@mikedelta658 Жыл бұрын
Thanks Dear!
@santoshbhupati3579
@santoshbhupati3579 Жыл бұрын
Thank you
@PRITYKUMARI-zn5ro
@PRITYKUMARI-zn5ro 2 жыл бұрын
your explanation is so smooth and clear.thanks. can you plz mention time complexity with your solution..it would be very useful.
@oiabhii
@oiabhii Жыл бұрын
Great explanation! please give time and space complexity too that would really help us all.
@davidl6797
@davidl6797 2 жыл бұрын
Thank you so much! Good explanation :)
@skp6753
@skp6753 Жыл бұрын
clear!!
@abhishekthakur7578
@abhishekthakur7578 Жыл бұрын
good explaination but please keep your speed slow we are just new in programming
@sreeharsha6383
@sreeharsha6383 2 жыл бұрын
but it is always recommended to do in constant space right ?
@newrolex8918
@newrolex8918 Жыл бұрын
your voice is so sweet and melodious
@omrajgure4553
@omrajgure4553 2 жыл бұрын
Your explanation and all are fantastic but I would like to give you a feedback about try keeping your mic slightly away...it irritates sometimes. Thank you :)
@machj2592
@machj2592 Жыл бұрын
i love you for this
@_Deepak__Verma
@_Deepak__Verma 8 ай бұрын
do it with recurrsion method because that is tricky
@karanpanchal5902
@karanpanchal5902 Жыл бұрын
I don't why know but i am getting this error as : error: not a statement l3->next=new ListNode(value % 10); ^ can you help with this?
@MindTransformer
@MindTransformer Жыл бұрын
same bro
@pratikbhange4780
@pratikbhange4780 2 жыл бұрын
Keep it up!!
@Soumyajit_619
@Soumyajit_619 9 ай бұрын
Can you tell me how did you get so good at this? It feels like you know every step as soon as you read the question, although I am new to coding I am completely lost here...
@mayankjaiswal568
@mayankjaiswal568 2 ай бұрын
Whats d point of doing that if we r taking new list It is advisable to do in same list without taking any extra space
@__ankush_kushwaha
@__ankush_kushwaha 2 жыл бұрын
mind blowing
@ashb8552
@ashb8552 Жыл бұрын
thx
@vaibhavgupta4720
@vaibhavgupta4720 Жыл бұрын
Mam in this video you just look like's , just now woke up 😁😁
@muhammadirahmonov417
@muhammadirahmonov417 2 жыл бұрын
good luck
@menapatigowrishankar6236
@menapatigowrishankar6236 Жыл бұрын
How do you gain this logic to solve this kind of probs, let me know please, any tips to solve..
@sumitftr
@sumitftr Жыл бұрын
I didn't noticed the reverse word in the question and tried to solve this problem with wrong concept for three days
@rts6649
@rts6649 2 жыл бұрын
Hey, can you just me how can I solve problem without getting errror. My solution is correct but keep saying error can u make video on that.
@priyanka4737
@priyanka4737 Жыл бұрын
same here - compilation error in line where we creating linklist
@jaydhanwalkar9665
@jaydhanwalkar9665 Жыл бұрын
what is time and space complexity of this code?
@prasanna9440
@prasanna9440 Жыл бұрын
The thing I've learnt is writing while(carry) exceeds time limit, so we write if(carry).. Thank you ma'am for this kind explanation 😊😊
@prachigupta7197
@prachigupta7197 Жыл бұрын
can u explain why it shows tle with while?
@technubie
@technubie 2 жыл бұрын
So cute 🥰
@17.shubhamashish27
@17.shubhamashish27 7 ай бұрын
nice way of teaching i've done some new watching your logic var addTwoNumbers = function (l1, l2) { let node = new ListNode(0) let curr = node; let carry = 0; let sum = 0; while (l1 || l2 || carry) { if (!l2) { l2 = new ListNode(0) } if (!l1) { l1 = new ListNode(0) } sum = l1.val + l2.val + carry carry = Math.floor(sum / 10) let r = sum % 10 curr.next = new ListNode(r) curr = curr.next l1 = l1.next l2 = l2.next } // if(carry){ // curr.next=new ListNode(carry) // } return node.next };
@AmoghSarangdhar
@AmoghSarangdhar 2 жыл бұрын
u deserve a subscribe
@infomania_by_ayush7901
@infomania_by_ayush7901 11 ай бұрын
So today, I was trying to add the numbers by storing in string and then reversing the string and what not and finally I cleared 1565 test cases failed 3. 😢😢
@RohitKumar-uz3hr
@RohitKumar-uz3hr Жыл бұрын
A beautiful girl with a beautiful explanation🙂🙂
@VivekPundir-r8e
@VivekPundir-r8e 25 күн бұрын
Mam mera output wrong aa rha hai
@sachinkapri4240
@sachinkapri4240 4 ай бұрын
Last test case still not working!
@krushnachandrajena6297
@krushnachandrajena6297 7 ай бұрын
Nice video,can i get the code?
@Programming-for-all-u2l
@Programming-for-all-u2l 10 ай бұрын
I need all problems and java
@SandeepSingh-nc1zm
@SandeepSingh-nc1zm 2 жыл бұрын
goodie
@technubie
@technubie 2 жыл бұрын
I wish you code in java also 😢
@ajitpalsingh606
@ajitpalsingh606 Жыл бұрын
243+564=807 not 708
@ritiknandanwar8198
@ritiknandanwar8198 2 жыл бұрын
Where are you placed currently? Nice vid though
@hameedmulani21
@hameedmulani21 2 жыл бұрын
Microsoft
@Piyush-wm2wj
@Piyush-wm2wj 9 ай бұрын
Sakal piche rakh kr bnaya jro
@spikemza6610
@spikemza6610 6 ай бұрын
she's not explaining she's just practicing herself worse kind of explanation
@fallen7
@fallen7 2 ай бұрын
Comeon man that was a fine explanation she cant teach u by grabbing your fingers
@amituknow2814
@amituknow2814 Жыл бұрын
video play karte ho to cute sa face dikha tumara, pyar ho gya :)
@amituknow2814
@amituknow2814 Жыл бұрын
nhi samaj aya, hindi me samghati to acha hota..kisi aur ki video dekhta hu
@ratneshtiwariaxiscollegesc7144
@ratneshtiwariaxiscollegesc7144 5 ай бұрын
You think yourself genius , worst kind of explanation, please first learn to explain
@projectsdb4034
@projectsdb4034 Жыл бұрын
//Java Code public ListNode addTwoNumbers(ListNode l1, ListNode l2) { ListNode l3 = new ListNode(0); ListNode head = new ListNode(); head = l3; int carry = 0; while(l1!=null && l2!=null){ int value = l1.val+l2.val+carry; carry = value/10; l3.next = new ListNode(value%10); l3 = l3.next; l2 = l2.next; l1 = l1.next; } while(l1!=null){ int value = l1.val+carry; carry = value/10; l3.next = new ListNode(value%10); l3 = l3.next; l1 = l1.next; } while(l2!=null){ int value = l2.val+carry; carry = value/10; l3.next = new ListNode(value%10); l3 = l3.next; l2 = l2.next; } if(carry>0){ l3.next = new ListNode(carry); } return head.next; } }
@abhishek6575
@abhishek6575 Жыл бұрын
leetcode easy sol by me class Solution { private: ListNode* reverse(ListNode* head) { ListNode* curr = head; ListNode* prev = NULL; ListNode* next = NULL; while(curr != NULL) { next = curr -> next; curr -> next = prev; prev = curr; curr = next; } return prev; } public: ListNode* addTwoNumbers(ListNode* lis1, ListNode* lis2) { ListNode*l1=reverse(lis1); ListNode*l2=reverse(lis2); ListNode*dummy=new ListNode(); ListNode*temp=dummy; int carry=0; while(l1!=NULL||l2!=NULL||carry){ int sum=0; sum=sum+carry; if(l1!=NULL){ sum+=l1->val; l1=l1->next;} if(l2!=NULL){ sum+=l2->val; l2=l2->next;} carry=sum/10; ListNode* node=new ListNode(sum%10);sum+=carry; temp->next=node; temp=temp->next; }temp=dummy; ListNode*curr=reverse(temp->next); return curr; } };
@hsg15
@hsg15 2 жыл бұрын
OP ma'am .. I'm getting u bit by bit every bit 🫡🔥
L5. Add 2 numbers in LinkedList | Dummy Node Approach
14:48
take U forward
Рет қаралды 116 М.
Python Programming Practice: LeetCode #2 -- Add Two Numbers
19:16
Симбу закрыли дома?! 🔒 #симба #симбочка #арти
00:41
Симбочка Пимпочка
Рет қаралды 5 МЛН
Hoodie gets wicked makeover! 😲
00:47
Justin Flom
Рет қаралды 138 МЛН
Thank you Santa
00:13
Nadir Show
Рет қаралды 36 МЛН
8 patterns to solve 80% Leetcode problems
7:30
Sahil & Sarra
Рет қаралды 442 М.
Add Two Numbers - Leetcode 2 - Python
9:33
NeetCode
Рет қаралды 261 М.
⚡️NEWS | RUBLE COLLAPSE | STRIKE ON CRIMEA | PUTIN IN KAZAKHSTAN
10:34
Ходорковский LIVE
Рет қаралды 192 М.
LeetCode Problem: 2. Add Two Numbers | Java Solution
19:25
Code for Interview
Рет қаралды 6 М.
❌ Don't Run Behind 500 LEETCODE Problems ❌ Focus on QPCD
8:31
Adding Two Numbers using Linked Lists - Part 1
18:34
Neso Academy
Рет қаралды 34 М.
L23. Merge two sorted Linked Lists
18:55
take U forward
Рет қаралды 72 М.
Симбу закрыли дома?! 🔒 #симба #симбочка #арти
00:41
Симбочка Пимпочка
Рет қаралды 5 МЛН