Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

two sum python

class Solution:
    def twoSum(self, nums: list[int], target: int) -> list[int]:
        required = {}
        for i in range(len(nums)):
            if target - nums[i] in required:
                return [required[target - nums[i]], i]
            else:
                required[nums[i]] = i
 
PREVIOUS NEXT
Tagged: #sum #python
ADD COMMENT
Topic
Name
7+9 =