Skip to content

Grind 75 - Two Sum

Posted on:July 21, 2023 at 02:36 PM at 1 min read

Solution for Two Sum problem which is a part of Grind 75 list.

class Solution:
    def twoSum(self, nums: List[int], target: int) -> List[int]:
        mapping = {}

        for idx, val in enumerate(nums):
            req = target-val
            if req in mapping:
                return [mapping[req], idx]
            mapping[val] = idx

        return []

Comments