【文件属性】:
文件名称:leetcode2sumc-leetcode-php:Leetcode在PHP上的解决方案
文件大小:3KB
文件格式:ZIP
更新时间:2021-07-06 17:50:20
系统开源
leetcode
2
和
c
力码
PHP
Leetcode
在
PHP
上的解决方案
简单的水平
1.
二和
显示解决方案
function
twoSum
(
$
nums
,
$
target
)
{
foreach
(
$
nums
as
$
key
=>
$
val
)
{
unset(
$
nums
[
$
key
]);
$
nextKey
=
array_search
((
$
target
-
$
val
),
$
nums
);
if
(
$
nextKey
)
{
return
[
$
key
,
$
nextKey
];
}
}
return
[];
}
7.
反转整数
显示解决方案
function
reverse
(
$
x
)
{
if
(
is_int
(
$
x
)
===
false
||
$
x
===
null
||
$
x
===
0
)
return
0
;
$
res
=
$
x
<
0
?
-
abs
(
strrev
(
$
x
))
:
(
int
)
strrev
(
$
x
);
if
(
$
res
<
-
2147483648
【文件预览】:
leetcode-php-main
----README.md(11KB)