Accepted Python code without hashing

  • 0
    class Solution(object):
        def twoSum(self, nums, target):
            :type nums: List[int]
            :type target: int
            :rtype: List[int]
            checked = []
            for i in range(len(nums)):
                diff = target-nums[i]
                if diff in checked:
                    return [nums.index(diff),i]

    My solution was accepted using only a list, but why many people uses dictionaries to hash values? I'd be happy to learn.

Log in to reply

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