Simple Python Implementation


  • 13
    A
    class Solution(object):
        def twoSum(self, nums, target):
            check = {}
            for i,num in enumerate(nums):
                if num not in check:
                    check[target-num]=i
                else:
                    return [min(i,check[num]),max(i,check[num])]

  • 2
    J

    just return [check[num],i] is enough


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.