第一次拿Python写,还不是很熟练,有点迷
class Solution(object):
def twoSum(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[int]
"""
dic = {};
for i in range(len(nums)):
#这里这个用法挺精髓的,运用字典的方法进行查找下标
if target - nums[i] in dic:
return [dic[target - nums[i]] + 1,i + 1]
dic[nums[i]] = i
初探Python编程:解决两数之和问题
2万+

被折叠的 条评论
为什么被折叠?



