0
点赞
收藏
分享

微信扫一扫

力扣-1. 两数之和 (Python)

题目难度

题目描述

提示

解题思路

方法2代码

def twoSum(self, nums: List[int], target: int) -> List[int]:
    mapp=dict()
    for i in range(len(nums)):
        x=nums[i]
        if target-x in mapp:
            return [mapp[target-x],i]
        mapp[x]=i #检查完再加入字典防止出现target=num1+num1

复杂度分析

举报

相关推荐

0 条评论