diff --git a/problems/0027.移除元素.md b/problems/0027.移除元素.md index e3b75719..886ce4f2 100644 --- a/problems/0027.移除元素.md +++ b/problems/0027.移除元素.md @@ -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) * B站视频:[代码随想录](https://space.bilibili.com/525438321)