Aaron2932

导航

ALGO-双指针

167. Two Sum II - Input Array Is Sorted

func twoSum(numbers []int, target int) []int {
	tmpMap := make(map[int]int, 10)

	for idx, val := range numbers {
		v, ok := tmpMap[target-val]
		if ok {
			return []int{v + 1, idx + 1}
		}
		tmpMap[val] = idx
	}
	return []int{-1, -1}
}

posted on 2022-08-01 00:39  Aaron2932  阅读(29)  评论(0)    收藏  举报