首页 > 其他 > 详细

leetcode--1

时间:2015-03-03 11:59:25      阅读:311      评论:0      收藏:0      [点我收藏+]
class Solution:
    # @return a tuple, (index1, index2)
    def twoSum(self, num, target):
        dictionary = {}
        for index, number in enumerate(num):
            dictionary[number] = index
        for indexCurrent, number in enumerate(num):
            diff = target - number
            index2 = dictionary.get(diff, 0)
            if index2 == indexCurrent:
                continue
            if index2:
                index1 = indexCurrent
                break
        return index1 + 1, index2 + 1


leetcode--1

原文:http://my.oschina.net/stevenKelly/blog/381734

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!