LeetCode做题记录(Python版)

1. 两数之和


点击查看折叠代码块

class Solution:
    def twoSum(self, nums: List[int], target: int) -> List[int]:
        dic = {}
        for i, x in enumerate(nums):
            dic[x] = i
        for i, x in enumerate(nums):
            if target - x in dic and dic[target - x] != i:
                return [i, dic[target - x]]
上一篇:从Python中的无限生成器获取子集列表


下一篇:枚举两个大数组的快速方法?