mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 11:34:46 +08:00
添加 0027.移除元素 PHP版本
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user