LeetCode #1 - Two Sum in Python (Multiple Solutions, Explanations and Complexity Analysis)

preview_player
Показать описание
Today we'll be solving the very popular interview question called "Two Sum". I will implement a brute force solution and then another solution that optimize speed using a hash table or dictionary in Python.
Рекомендации по теме
Комментарии
Автор

Thank you sir. Great explanations. Keep this series going.

phucinminnesota
Автор

Please do more of these. Learning a lot from them. Many thanks.

mwsentertainment
Автор

num=[2, 7, 11, 15]
target=9
count=0
first=num[count]
final=[]
for i in range(1, len(num)):
desired=target-first
if num[i]==desired:
final.append(count)
final.append(i)
else:
count+=1
print(final)

ujjwaljain
Автор

Hi Michael, thanks for the video, I understood eveything perfect, however, I want to go one step forward and try to reach a code which works when we have more than one possible solution, for example:

nums = [2, 3, 7, 1, 4]
target = 5

We would have two solutions: (0, 1) aand (3, 4).

How would that be coded?

joseangelmartinez
visit shbcf.ru