风趣饼干

文章
5
资源
0
加入时间
3年1月10天

Leetcode 1.两数之和 Python

class Solution: def twoSum(self, nums, target): for i,n in enumerate(nums): if target-n in nums and nums.index(target-n)!=i: return [i,nums.index(target-n)]解题思路:遍历数组里的每一个数字用和-加数求出另一个加数再判断求出的数字是否位于数组中并且这个数字.