【文件属性】:
文件名称:leetcode数组下标大于间距-LeetCode:力码
文件大小:112KB
文件格式:ZIP
更新时间:2021-06-30 17:09:03
系统开源
leetcode
数组下标概率力码
[目录]
算法
1.
二和
Given
an
array
of
integers,
return
indices
of
the
two
numbers
such
that
they
add
up
to
a
specific
target.
创建一个字典dic:target
-
nums[i]
:
i
,对列表进行遍历,如果nums[i]在dic中,则搜索成功。
dic
=
{}
for
i
in
range
(
len
(
nums
)):
if
nums
[
i
]
in
dic
:
return
[
dic
[
nums
[
i
]],
i
]
else
:
dic
[
target
-
nums
[
i
]]
=
i
###2.添加两个数字
Input:
(2
->
4
->
3)
+
(5
->
6
->
4)
Output:
7
->
0
->
8
carry
=
0
ans
=
cur
=
ListNode
(
0
)
while
l1
or
l2
or
carry
:
if
l1
:
carry
+=
l1
.
val