其他分享
首页 > 其他分享> > ALGO-双指针

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}
}

标签:return,val,idx,int,tmpMap,ALGO,numbers,指针
来源: https://www.cnblogs.com/aaron2932/p/16538755.html