zoukankan      html  css  js  c++  java
  • [LeetCode] 1. Two Sum

    __author__ = 'zenglinwang'
    
    class Solution(object):
    
        def twoSum(self, nums, target):
            """
            :type nums: List[int]
            :type target: int
            :rtype: List[int]
            """
    
            map = dict()
    
            # Since two numbers are mutually complemented, one pass hash table can do.
            for i in range(0, len(nums)):
                complement = target - nums[i]
                # print "- [{0:d},{1:d}]".format(nums[i], i)
                # print map.items()
                if complement in map.keys() and map.get(complement) != i:
                    # print "[{0:d},{1:d}]".format(map.get(complement), i)
                    return [map.get(complement), i]
                map[nums[i]] = i
    
    # s = Solution()
    # s.twoSum([0,4,3,4,5,4], 8)
  • 相关阅读:
    BaseJob
    BaseWorkerForm
    MainForm()
    OperationSystemForm
    Job1
    ExeCuteManager
    ThreadPool
    LogEntry
    java学习阶段一 常量
    java学习阶段一 数据类型
  • 原文地址:https://www.cnblogs.com/skyssky/p/5740405.html
Copyright © 2011-2022 走看看