Two Sum

Problem Id: 1 Difficulty: Easy Tag: Array Tag: Hash Table


Intuition

This is a simple problem. Just use hash table.

Solution


class Solution:
    def twoSum(self, nums, target):
        indexes = {}
        for j, num in enumerate(nums):
            if target - num in indexes:
                return [indexes[target - num], j]
            indexes[num] = j