标签:
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
标签:
原文地址:http://my.oschina.net/stevenKelly/blog/381734