Untitled

Anonymous
golang
06/15/2023 9:14 AM
388 B
19
Indexable
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
}
Editor is loading...