码迷,mamicode.com
首页 > 其他好文 > 详细

Two Sum

时间:2016-10-06 22:00:04      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

题目如下:

技术分享

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

 

Two Sum

标签:

原文地址:http://www.cnblogs.com/CQUTWH/p/5934600.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!