给一个int型数组无序,从数组中选出两数字,使得这两数字之和为target,将这两数字的下标作为数组返回。(一定存在一个解)
注意:对代码进行优化,可能会超时。
Given nums = [2, 7, 11, 15], target = 9,
Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1]. ##
本文介绍了一种算法,该算法接收一个整数数组和一个目标值,通过查找数组中两个数相加等于目标值的元素,并返回这两个元素的索引。
注意:对代码进行优化,可能会超时。
Given nums = [2, 7, 11, 15], target = 9,
Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1]. ##
490

被折叠的 条评论
为什么被折叠?