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

preview_player
Показать описание
In this episode of Python Programming Practice: LeetCode #2 -- Add Two Numbers.

Link to the problem here:

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. .

Рекомендации по теме
Комментарии
Автор

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

francescaerreia
Автор

That is amazing. So clear than any other solution I have seen.

xuebindong
Автор

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.

TDMac
Автор

I love your videos, they are super helpful and clear! Thanks for making these

NebulousFantasy
Автор

Nice Explaintion...really amazing. i'm supporting you onwards so just keep going. Thanks

TrendingInfo
Автор

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.

laax
Автор

Man you're so talented, THANK YOU!💖

droxt
Автор

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):


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...

crimsonair
Автор

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. 😅

rafaeldesantis
Автор

Can someone explain me what does .next mean in this one ?

jossuerguillen
Автор

what's the purpose of val and next?

sangpark
Автор

How to run these codes? Im pretty new and work in jupyter notebook

arjunkc
Автор

Nice explanation but when i executed this code there no result that I see what happened plz

dhibyar_hussein
Автор

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.

danielsun
Автор

How would I run this code in VScode so I can test and debug?

wesleyurena
Автор

What does Listnode(val. = (l1.val + l2.val) % 10 ) do?

sangpark
Автор

Sir you remind me of sheldon cooper from TBBT !!

ryanmanchikanti
Автор

I can’t watch this video just as I was watching

xephyr