Untitled

mail@pastecode.io avatar
unknown
golang
a year ago
290 B
9
Indexable
Never
func twoSum(nums []int, target int) (int, int) {
	
	complementMap := make(map[int]int)

	for i, num := range nums {
		complement := target - num

	
		if index, ok := complementMap[complement]; ok {
			return index, i
		}

		
		complementMap[num] = i
	}

	
	return -1, -1
}