添加 0001.两数之和 PHP版本

This commit is contained in:
nolanzzz
2021-09-02 23:50:54 -04:00
parent 485f6a806a
commit 7f7d1eed32

View File

@ -224,6 +224,31 @@ func twoSum(_ nums: [Int], _ target: Int) -> [Int] {
}
```
PHP:
```php
class Solution {
/**
* @param Integer[] $nums
* @param Integer $target
* @return Integer[]
*/
function twoSum($nums, $target) {
if (count($nums) == 0) {
return [];
}
$table = [];
for ($i = 0; $i < count($nums); $i++) {
$temp = $target - $nums[$i];
if (isset($table[$temp])) {
return [$table[$temp], $i];
}
$table[$nums[$i]] = $i;
}
return [];
}
}
```
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频[代码随想录](https://space.bilibili.com/525438321)