Here's the solution:
def two_sum(nums, target):
seen = {}
for i, num in enumerate(nums):
complement = target - num
if complement in seen:
return [seen[complement], i]
seen[num] = i
return []
For each number, check if its complement was seen before. If yes, return both indices. If not, store this number's index.