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; }
@lifekool58382 жыл бұрын
in depth knowledge of how to solve a particular problem and how to take care of edge cases. Best explanation ever
@ParthG-vi4ml10 ай бұрын
really 😃 breaking down the problem into smaller chunks & solving every chunk 1 by 1 is the best thing of this channel.
@DG_Theniel5 ай бұрын
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 Жыл бұрын
I see many videos, but you explain very well. Best explanation and easy to understand.
@SleepyBaseball-ts7se10 ай бұрын
Ma'am, I'm working with java but I got complete logic of the code Hats off to you Ma'am
@viencong2 жыл бұрын
100 point for you. Love you very much for explain so eassy to understand
@rakeshruler25242 жыл бұрын
You explained it in student way thank you for the simple logic ! A lots of love
@MdineshKumar-gp9wg2 жыл бұрын
i started coding last few weeks.your viedoes was so helpful to me .thank you
@probabilitycodingisfunis12 жыл бұрын
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 Жыл бұрын
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 Жыл бұрын
@@saijeswanth6673 if you working in java use ListNode l3 = new ListNode (0);
@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; } }
@ashishshetty43639 ай бұрын
@@shubhamkate7849 can anyone explain why her code is not working
@namrathas5804 Жыл бұрын
Thank you so much Alisha, your code and explanation was so easy to understand.
@nakuldeshmukh79012 жыл бұрын
best explanation of this problem on yt. Very simple to understand .Kudos!
@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........
@honey65672 жыл бұрын
VERY GOOD EXPLANATION KEEP MORE MORE VIDEOS IN LEET CODE THANKS
@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🙏
@darshanpancholi874610 ай бұрын
just loved the way you explained....❤❤
@himanshugupta36992 жыл бұрын
You have no idea how confused I was in this..Thankyou for making this video
@zeyadalbadawy2245 Жыл бұрын
Alish , your explaination is unparallel !!
@imran3509 Жыл бұрын
Gajab bhai mast samjhaya
@hemantdixit40582 жыл бұрын
so much clarity in your explanation, amazing
@Modern_Monk89262 ай бұрын
You know what you just gained one more subscriber😊😊 by the way thanks for the explanation
@syedmunawar98092 жыл бұрын
I am begining to code and your video is helpful
@muhsinmansooriee_00172 жыл бұрын
this is the first video on youtube that truly made me feel to subscribe. Thanks a lot.
@probabilitycodingisfunis12 жыл бұрын
Thank you so much Muhsin
@soumyadas9002 жыл бұрын
ju ke ho kya ?
@muhsinmansooriee_00172 жыл бұрын
@@soumyadas900 haan 🥲
@TeachingCodes Жыл бұрын
Nice Explanation, Keep it up
@cse07982 жыл бұрын
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-du2nu10 ай бұрын
superb teaching skill
@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 🙏🙏🙏
@PranavKamathe4 ай бұрын
Thank you Didi...!!✨
@Khabib901 Жыл бұрын
Great Explanation
@anikmahmud17482 жыл бұрын
carry on sister.your explanation is better than any other explanation❤❤❤❤❤
@florianion46332 жыл бұрын
omg so much work put into this channel. thx for help and great work
@AbhiWarrior12211 ай бұрын
nice explaination Didi it really helps
@tamzeedahmed153611 ай бұрын
Great explanation!!
@HARIHARAKRA2 жыл бұрын
Your explaination is soothing..keep going mam
@tarushidubey2973 Жыл бұрын
very well explained di
@sharadkumar66582 жыл бұрын
Nice mam. It was really good.😇😇
@34adnanali26Күн бұрын
great
@adyamansingh2983 Жыл бұрын
amazing explaination
@hameedmulani212 жыл бұрын
Best explanation
@mukulyadav655 Жыл бұрын
your codes are really helpful thanks
@anshulvats15702 жыл бұрын
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
@probabilitycodingisfunis12 жыл бұрын
Awesome! Keep practising Anshul !
@17.shubhamashish277 ай бұрын
nice explaination
@KaushalSharma-yo2yu Жыл бұрын
perfect example of beauty with brain
@KartikSharma-yi4vg Жыл бұрын
Very Good Video
@luckylam1181 Жыл бұрын
Thanks for the great explanation!
@Coding-Just Жыл бұрын
Thanks a lot 👍👍👍
@sayankarmakar138 ай бұрын
Appreciated ❤
@vitaminprotein22172 жыл бұрын
A hardstuck will always understand from you :D
@projectsdb4034 Жыл бұрын
Thanks Great Logic
@Basantkumarr Жыл бұрын
Amazing explanation 😊 please make more videos
@adarshkumargupta.2 жыл бұрын
vey nice explanation
@mikedelta658 Жыл бұрын
Thanks Dear!
@santoshbhupati3579 Жыл бұрын
Thank you
@PRITYKUMARI-zn5ro2 жыл бұрын
your explanation is so smooth and clear.thanks. can you plz mention time complexity with your solution..it would be very useful.
@oiabhii Жыл бұрын
Great explanation! please give time and space complexity too that would really help us all.
@davidl67972 жыл бұрын
Thank you so much! Good explanation :)
@skp6753 Жыл бұрын
clear!!
@abhishekthakur7578 Жыл бұрын
good explaination but please keep your speed slow we are just new in programming
@sreeharsha63832 жыл бұрын
but it is always recommended to do in constant space right ?
@newrolex8918 Жыл бұрын
your voice is so sweet and melodious
@omrajgure45532 жыл бұрын
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 Жыл бұрын
i love you for this
@_Deepak__Verma8 ай бұрын
do it with recurrsion method because that is tricky
@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 Жыл бұрын
same bro
@pratikbhange47802 жыл бұрын
Keep it up!!
@Soumyajit_6199 ай бұрын
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...
@mayankjaiswal5682 ай бұрын
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_kushwaha2 жыл бұрын
mind blowing
@ashb8552 Жыл бұрын
thx
@vaibhavgupta4720 Жыл бұрын
Mam in this video you just look like's , just now woke up 😁😁
@muhammadirahmonov4172 жыл бұрын
good luck
@menapatigowrishankar6236 Жыл бұрын
How do you gain this logic to solve this kind of probs, let me know please, any tips to solve..
@sumitftr Жыл бұрын
I didn't noticed the reverse word in the question and tried to solve this problem with wrong concept for three days
@rts66492 жыл бұрын
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 Жыл бұрын
same here - compilation error in line where we creating linklist
@jaydhanwalkar9665 Жыл бұрын
what is time and space complexity of this code?
@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 Жыл бұрын
can u explain why it shows tle with while?
@technubie2 жыл бұрын
So cute 🥰
@17.shubhamashish277 ай бұрын
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 };
@AmoghSarangdhar2 жыл бұрын
u deserve a subscribe
@infomania_by_ayush790111 ай бұрын
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 Жыл бұрын
A beautiful girl with a beautiful explanation🙂🙂
@VivekPundir-r8e25 күн бұрын
Mam mera output wrong aa rha hai
@sachinkapri42404 ай бұрын
Last test case still not working!
@krushnachandrajena62977 ай бұрын
Nice video,can i get the code?
@Programming-for-all-u2l10 ай бұрын
I need all problems and java
@SandeepSingh-nc1zm2 жыл бұрын
goodie
@technubie2 жыл бұрын
I wish you code in java also 😢
@ajitpalsingh606 Жыл бұрын
243+564=807 not 708
@ritiknandanwar81982 жыл бұрын
Where are you placed currently? Nice vid though
@hameedmulani212 жыл бұрын
Microsoft
@Piyush-wm2wj9 ай бұрын
Sakal piche rakh kr bnaya jro
@spikemza66106 ай бұрын
she's not explaining she's just practicing herself worse kind of explanation
@fallen72 ай бұрын
Comeon man that was a fine explanation she cant teach u by grabbing your fingers
@amituknow2814 Жыл бұрын
video play karte ho to cute sa face dikha tumara, pyar ho gya :)
@amituknow2814 Жыл бұрын
nhi samaj aya, hindi me samghati to acha hota..kisi aur ki video dekhta hu
@ratneshtiwariaxiscollegesc71445 ай бұрын
You think yourself genius , worst kind of explanation, please first learn to explain
@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 Жыл бұрын
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; } };