【leetcode❤python】 1. Two Sum

#-*- 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)

posted @ 2016-11-13 19:23  火金队长  阅读(158)  评论(0编辑  收藏  举报