【文件属性】:
文件名称:leetcode走方格起点到终点-LeetCode_Record:LeetCode刷题记录
文件大小:122KB
文件格式:ZIP
更新时间:2021-06-30 06:13:42
系统开源
leetcode走方格起点到终点
LeetCode_Record(easy
1-20)
Two
Sum
题目:
Given
an
array
of
integers,
return
indices
of
the
two
numbers
such
that
they
add
up
to
a
specific
target.
You
may
assume
that
each
input
would
have
exactly
one
solution,
and
you
may
not
use
the
same
element
twice.
例子:
Given
nums
=
[2,
7,
11,
15],
target
=
9,
Because
nums[0]
+
nums[1]
=
2
+
7
=
9,
return
[0,
1].
题意分析:
找出数组numbers中的两个数,它们的和为给定的一个数target,并返回这两个数的索引(不需要去重)
思路分析
题目要求说白了就是找出这个给的数组中有哪两个数相加等于目标结果
方法一
很容易想到我们可以遍历两次数组,在内循环中判断两次循环中的数相