添加 0027.移除元素 PHP版本

This commit is contained in:
nolanzzz
2021-09-01 18:56:34 -04:00
parent 325a09cee7
commit 3441bced12

View File

@ -246,6 +246,31 @@ func removeElement(_ nums: inout [Int], _ val: Int) -> Int {
}
```
PHP:
```php
class Solution {
/**
* @param Integer[] $nums
* @param Integer $val
* @return Integer
*/
function removeElement(&$nums, $val) {
if (count($nums) == 0) {
return 0;
}
// 快慢指针
$slow = 0;
for ($fast = 0; $fast < count($nums); $fast++) {
if ($nums[$fast] != $val) {
$nums[$slow] = $nums[$fast];
$slow++;
}
}
return $slow;
}
}
```
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频[代码随想录](https://space.bilibili.com/525438321)