首页 > 技术文章 > LeetCode(1)Two Sum

CQUTWH 2016-10-06 19:33 原文

题目如下:

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

 

推荐阅读