return indices of the two numbers that add up to a number python code example
Example: two sum in python with 0ms runtime
def twoSum(self, nums: List[int], target: int) -> List[int]: dictionary = {} answer = [] for i in range(len(nums)): secondNumber = target-nums[i] if(secondNumber in dictionary.keys()): secondIndex = nums.index(secondNumber) if(i != secondIndex): return sorted([i, secondIndex]) dictionary.update({nums[i]: i})