1.两数之和

from typing import List


class Solution:
    def twoSum(self, nums: List[int], target: int) -> List[int]:
        """
        【空间换时间】
        哈希表解法,将值与下标存在哈希表内,遍历时拿和值-当前值=目标值
        再判断目标值是否存在哈希表中,如果存在直接返回

        Args:
            nums (List[int]): _description_
            target (int): _description_

        Returns:
            List[int]: _description_
        """
        map = {}
        for index, value in enumerate(nums):
            result = target - value
            if result in map:
                return [map[result], index]
            map[value] = index
        return []


print(Solution().twoSum([3, 3], 6))