leetcode two sum python

class Solution:
    # @param {integer[]} nums
    # @param {integer} target
    # @return {integer[]}
    def twoSum(self, nums, target):
        intLen=len(nums)
        if intLen <=1:
            return False
        res=[]
        dicts={}
        for i in range(0,intLen):
            if not dicts.has_key(target-nums[i]):
                dicts[nums[i]]=i
            else:
                tmpIndex=target-nums[i]
                res.append(dicts[tmpIndex]+1)
                res.append(i+1)
        return res 

 

posted @ 2015-09-27 23:56  hao.ma  阅读(133)  评论(0编辑  收藏  举报