Login light

https://leetcode-cn.com/problems/two-sum/submissions/

19年12月的答案

class Solution:
    def twoSum(self, nums: List[int], target: int) -> List[int]:
        for i in range(len(nums)):
            val = target - nums[i]
            if val in nums[i+1:]:
                return [i,nums[i+1:].index(val)+i+1]

19年5月的答案

class Solution:
    def twoSum(self, nums: List[int], target: int) -> List[int]:
        for k1 in range(len(nums)):
            v1=nums[k1]
            tmp = target - v1
            if tmp in nums:
                k2 = nums.index(tmp)
                if k1!=k2:
                    return [k1,k2]