mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
添加 0027.移除元素.md C语言版本
This commit is contained in:
@ -246,6 +246,23 @@ func removeElement(_ nums: inout [Int], _ val: Int) -> Int {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
C:
|
||||||
|
```c
|
||||||
|
int removeElement(int* nums, int numsSize, int val){
|
||||||
|
int slow = 0;
|
||||||
|
for(int fast = 0; fast < numsSize; fast++) {
|
||||||
|
//若快指针位置的元素不等于要删除的元素
|
||||||
|
if(nums[fast] != val) {
|
||||||
|
//将其挪到慢指针指向的位置,慢指针+1
|
||||||
|
nums[slow++] = nums[fast];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//最后慢指针的大小就是新的数组的大小
|
||||||
|
return slow;
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
-----------------------
|
-----------------------
|
||||||
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
|
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
|
||||||
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
|
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
|
||||||
|
Reference in New Issue
Block a user