【leetcode❤python】 1. Two Sum

时间:2022-05-05 19:28:45

#-*- coding: UTF-8 -*-
#AC源码【意外惊喜,还以为会超时】
class Solution(object):
    def twoSum(self, nums, target):
        """
        :type nums: List[int]
        :type target: int
        :rtype: List[int]
        """
 
        for i in xrange(len(nums)):
            
            tmp=target-nums[i]
            curList=nums[i+1:]
     
            if curList.__contains__(tmp):
                return [i,i+curList.index(tmp)+1]
            else:continue
        return []

sol=Solution()
print sol.twoSum([-1,-2,-3,-4,-5],-8)