Тёмный

Python Programming Practice: LeetCode #2 -- Add Two Numbers 

DataDaft
Подписаться 48 тыс.
Просмотров 38 тыс.
50% 1

In this episode of Python Programming Practice: LeetCode #2 -- Add Two Numbers.
Link to the problem here:
leetcode.com/p...
If you don't know Python, you can learn the basics of Python for data analysis by following along with this RU-vid guide I created: • Python for Data Analysis
Python Programming Practice is a series focused on teaching practical coding skills by solving exercises on popular coding websites. Note that the solutions seen here may not be the most efficient possible.
I am not going to provide the full code in the video description for this series, since copy and pasting solutions is not in the spirit of doing coding exercises. It is intended that the video will help you think about problems, approaches and how to structure solutions so that you are able to code up a working solution yourself. .
⭐ Kite is a free AI-powered coding assistant that integrates with popular editors and IDEs to give you smart code completions and docs while you’re typing. It is a cool application of machine learning that can also help you code faster! Check it out here: www.kite.com/g...

Опубликовано:

 

26 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 35   
@xuebindong4803
@xuebindong4803 3 года назад
That is amazing. So clear than any other solution I have seen.
@francescaerreia8859
@francescaerreia8859 2 года назад
You could do an “or” instead of an “and”, that way you only use one while loop, inside of which you set the val of a missing node to zero
@TDMac11
@TDMac11 4 месяца назад
Thanks so much for this, I typically use SQL but have to take a CodeSignal assessment and Python is my best option. I've been watching so many videos and none seem to click but yours have. I'm going to go through all of your leet code examples and hopefully it clicks.
@NebulousFantasy
@NebulousFantasy 3 года назад
I love your videos, they are super helpful and clear! Thanks for making these
@DataDaft
@DataDaft 3 года назад
I'm glad you found it useful!
@DIZZLEBOI44
@DIZZLEBOI44 2 года назад
@@DataDaft this is the best explanation I've seen thus far. Is there a way to connect?? I need 5p practice more
@wildworldexplorerstv
@wildworldexplorerstv 3 месяца назад
Best explanation so far!
@pawan-54646
@pawan-54646 3 года назад
Nice Explaintion...really amazing. i'm supporting you onwards so just keep going. Thanks
@mryup6100
@mryup6100 11 месяцев назад
Your teaching style is awesome!
@laax
@laax 4 года назад
Your leetcode videos are great, it is easy for me to follow your logic and I like how you explain the algorithms. One Idea for improvement: start considering time and space complexity and how to optimize your code based on that.
@DataDaft
@DataDaft 4 года назад
Glad you found them useful and thanks for the input. I do consider computational complexity for some of the solutions where it may be necessary to do better than brute force to pass the auto checker. In general I don't think it is that important to place at a high percentile for speed when submitting to to Leetcode (unless you are a lot slower than average), since speed can vary quite a bit from run to run. I'm more interested in the theoretical space/time complexity of the code, but I'll perhaps give a bit more thought to emphasizing that in the future.
@droxt
@droxt 2 года назад
Man you're so talented, THANK YOU!💖
@rafaeldesantis4259
@rafaeldesantis4259 Год назад
Great video, thanks for the lesson. I still have a question tho, it is probably a silly question but: When/Where does the added variable get reassigned? I mean, we looped through and stored the values in current_node, but why when we return (added) it retrieves the right ListNode? I don't get that part tbh. 😅
@kelseyarthur6421
@kelseyarthur6421 2 года назад
Love this series
@crimsonair8890
@crimsonair8890 2 года назад
I succeeded with a normal list, but I'm not sure why it doesn't work with the lists presented in the leetcode problem. Here is my code: l1 = [2,4,3] l2 = [5,6,4] l3 = [] value1 = 0 value2 = 0 value3 = 0 for i in range(len(l1)): value1 += 10**i * l1[i] for j in range(len(l2)): value2 += 10**j * l2[j] value3 = value1 + value2 lengthValue3 = len(str(value3)) for n in range(lengthValue3): l3.append(str(value3)[lengthValue3-n-1]) print(l3) Leetcode says l1 doesn't have a length, and I don't quite get that. How does a list not have a length? Isn't the length of l1 3, since there are three values in the list? It works on my normal IDE...
@fredneilson8904
@fredneilson8904 9 месяцев назад
i did the same in an IDE, this was my code: list = [] carry = 0 for a, b in zip(l1, l2): if a+b >= 10: x = a + b + carry carry = x // 10 list.append(x % 10) else: final = a + b list.append(final) and it worked just fine but leetcode didn't like it lmao
@luisaceo00
@luisaceo00 2 года назад
Thanks for the videos!!
@sangpark7656
@sangpark7656 Год назад
what's the purpose of val and next?
@arjunkc3227
@arjunkc3227 Год назад
How to run these codes? Im pretty new and work in jupyter notebook
@dhibyar_hussein2017
@dhibyar_hussein2017 2 года назад
Nice explanation but when i executed this code there no result that I see what happened plz
@sangpark7656
@sangpark7656 Год назад
is val the index number?
@wesleyurena2217
@wesleyurena2217 Год назад
How would I run this code in VScode so I can test and debug?
@jossuerguillen4550
@jossuerguillen4550 Год назад
Can someone explain me what does .next mean in this one ?
@sangpark7656
@sangpark7656 Год назад
What does Listnode(val. = (l1.val + l2.val) % 10 ) do?
@vigneshwari3247
@vigneshwari3247 4 месяца назад
If you’re still wondering this is where we store our result node by adding list nodes l1 & l2(added). And it gets initialised
@danielsun716
@danielsun716 2 года назад
Thanks for sharing, this is a great answer to understand the algorithm. But one quick question, why it is "return added" at last? I think added is still "ListNode(val = (l1.val + l2.val) % 10)", cause everything changed in current_node, right? added is not changed.
@slighttilt01
@slighttilt01 2 года назад
sorry for a late reply, but I think that the "current_node = added" line signifies that the current node lines are updating the "added" variable as you go through the code.
@thesamarthshah
@thesamarthshah 2 года назад
@@slighttilt01 how?
@thesamarthshah
@thesamarthshah 2 года назад
yes i conclude same. I haven't executed it yet though
@neiljohn2637
@neiljohn2637 Год назад
Hi bro... how much have you improved in your coding skills and how was u journey.. Coz I got the same doubt and I feel my current level is equal to urs about an year ago..
@neiljohn2637
@neiljohn2637 Год назад
.
@HAJAR-n9p
@HAJAR-n9p Месяц назад
i did not understand haha omggg
@xephyr2371
@xephyr2371 4 года назад
I can’t watch this video just as I was watching !!!!!
@HAJAR-n9p
@HAJAR-n9p Месяц назад
i did not understand hah omg
@ryanmanchikanti5265
@ryanmanchikanti5265 3 года назад
Sir you remind me of sheldon cooper from TBBT !!
Далее
Китайка и Максим Крипер😂😆
00:21
Being Competent With Coding Is More Fun
11:13
Просмотров 78 тыс.
Please Master These 10 Python Functions…
22:17
Просмотров 163 тыс.
Add Two Numbers - Leetcode 2 - Python
9:33
Просмотров 246 тыс.
Bjarne Stroustrup: C++ | Lex Fridman Podcast #48
1:47:13
Python Decorators in 15 Minutes
15:14
Просмотров 443 тыс.
How I Got Good at Coding Interviews
6:29
Просмотров 1,6 млн
Китайка и Максим Крипер😂😆
00:21