LeetCode(1)Two Sum

题目如下:

Python代码:

def twoSum(self, nums, target):
        """
        :type nums: List[int]
        :type target: int
        :rtype: List[int]
        """
        temp = []
        result = []
        for i in range(len(nums)):
            if temp.count(target-nums[i])!=0:
                result.append(nums.index(target-nums[i]))
                result.append(i)
            if temp.count(nums[i])==0:
                temp.append(nums[i])
        return result

 

posted @ 2016-10-06 19:33  Single、Dog  阅读(160)  评论(0编辑  收藏  举报