不挂科搜题免费

问题:

题目一:给定一个长度为n的整型数组nums,你需要计算出数组中的两个元素,使其和等于目标值targe

答案:

解```pythondef twoSum(nums, target):hashmap = {}for i, num in enumerate(nums):complement = target - numif complement in hashmap:return [hashmap[complement], i]hashmap[num] = ireturn []```