two sum dictionary python solution 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})